Add object detection, tracking, mobile notifications, and search to any security camera.
notifications knob
roryclear1d78f50fc1e2
diff --git a/clearcam/AppDelegate.m b/clearcam/AppDelegate.mindex f29c2ec..cd28c24 100644--- a/clearcam/AppDelegate.m+++ b/clearcam/AppDelegate.m@@ -12,25 +12,14 @@NSLog(@"App launched with options: %@", launchOptions);UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];center.delegate = self;-- [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge)- completionHandler:^(BOOL granted, NSError * _Nullable error) {- if (granted) {- dispatch_async(dispatch_get_main_queue(), ^{- [application registerForRemoteNotifications];- });- } else {- NSLog(@"Notification permission denied: %@", error);- }- }];-+// Handle launch from notificationif (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) {NSDictionary *userInfo = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];self.pendingNotification = userInfo;NSLog(@"Launched from notification: %@", userInfo);- // Only run background code if content-available is present (receipt, not tap)- if (userInfo[@"aps"][@"content-available"]) {+ // Only process if notifications are enabled+ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"receive_notif_enabled"] && userInfo[@"aps"][@"content-available"]) {[self handleNotificationReceived:userInfo];}}@@ -40,7 +29,7 @@- (void)applicationDidBecomeActive:(UIApplication *)application {NSLog(@"Application became active");- if (self.pendingNotification) {+ if (self.pendingNotification && [[NSUserDefaults standardUserDefaults] boolForKey:@"receive_notif_enabled"]) {[self handleNotificationNavigation];self.pendingNotification = nil;}@@ -83,7 +72,7 @@- (void)handleNotificationReceived:(NSDictionary *)userInfo {NSLog(@"Notification received (user did NOT tap): %@", userInfo);GalleryViewController *gallery = [[GalleryViewController alloc] init];- sleep(15);+ sleep(15); // Consider replacing this with a proper async operation[gallery getEvents];}@@ -110,10 +99,14 @@withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {NSDictionary *userInfo = notification.request.content.userInfo;NSLog(@"Will present notification: %@", userInfo);- if (userInfo[@"aps"][@"content-available"]) {- [self handleNotificationReceived:userInfo];+ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"receive_notif_enabled"]) {+ if (userInfo[@"aps"][@"content-available"]) {+ [self handleNotificationReceived:userInfo];+ }+ completionHandler(UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionSound);+ } else {+ completionHandler(0); // No presentation options when disabled}- completionHandler(UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionSound);}- (void)userNotificationCenter:(UNUserNotificationCenter *)center@@ -121,8 +114,9 @@ didReceiveNotificationResponse:(UNNotificationResponse *)responsewithCompletionHandler:(void (^)(void))completionHandler {NSDictionary *userInfo = response.notification.request.content.userInfo;NSLog(@"User tapped notification: %@", userInfo);- // Only handle navigation, no custom code here- [self handleNotificationNavigation];+ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"receive_notif_enabled"]) {+ [self handleNotificationNavigation];+ }completionHandler();}@@ -131,6 +125,11 @@ didReceiveRemoteNotification:(NSDictionary *)userInfofetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {NSLog(@"Received remote notification: %@", userInfo);+ if (![[NSUserDefaults standardUserDefaults] boolForKey:@"receive_notif_enabled"]) {+ completionHandler(UIBackgroundFetchResultNoData);+ return;+ }+if (userInfo[@"aps"][@"content-available"]) {NSLog(@"Background notification detected");dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{diff --git a/clearcam/SettingsViewController.m b/clearcam/SettingsViewController.mindex 00f9110..25ad6dd 100644--- a/clearcam/SettingsViewController.m+++ b/clearcam/SettingsViewController.m@@ -5,6 +5,7 @@#import "NumberSelectionViewController.h"#import "Email.h"#import "ScheduleManagementViewController.h"+#import <UserNotifications/UserNotifications.h>@interface SettingsViewController () <UITableViewDelegate, UITableViewDataSource>@@ -129,7 +130,20 @@[self.tableView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor]]];- [self.tableView reloadData];+ // Ensure switch reflects current permission state+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];+ [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {+ dispatch_async(dispatch_get_main_queue(), ^{+ if (settings.authorizationStatus == UNAuthorizationStatusAuthorized) {+ self.receiveNotifEnabled = [defaults boolForKey:@"receive_notif_enabled"];+ } else {+ self.receiveNotifEnabled = NO;+ [defaults setBool:NO forKey:@"receive_notif_enabled"];+ [defaults synchronize];+ }+ [self.tableView reloadData];+ });+ }];}- (void)dealloc {@@ -165,17 +179,68 @@}- (void)receiveNotifSwitchToggled:(UISwitch *)sender {- self.receiveNotifEnabled = sender.on;NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];+ BOOL hasRequestedPermission = [defaults boolForKey:@"hasRequestedNotificationPermission"];++ self.receiveNotifEnabled = sender.on;[defaults setBool:self.receiveNotifEnabled forKey:@"receive_notif_enabled"];[defaults synchronize];-+if (sender.on) {NSLog(@"Receive Notifications on This Device turned ON");- [[UIApplication sharedApplication] registerForRemoteNotifications];++ if (!hasRequestedPermission) {+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];+ [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge)+ completionHandler:^(BOOL granted, NSError * _Nullable error) {+ dispatch_async(dispatch_get_main_queue(), ^{+ if (granted) {+ NSLog(@"Notification permission granted");+ [[UIApplication sharedApplication] registerForRemoteNotifications];+ [defaults setBool:YES forKey:@"hasRequestedNotificationPermission"];+ [defaults synchronize];+ } else {+ NSLog(@"Notification permission denied: %@", error);+ self.receiveNotifEnabled = NO;+ [defaults setBool:NO forKey:@"receive_notif_enabled"];+ [defaults synchronize];+ sender.on = NO;++ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Permission Denied"+ message:@"Notification permission was denied. You can enable it in Settings."+ preferredStyle:UIAlertControllerStyleAlert];+ [alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];+ [self presentViewController:alert animated:YES completion:nil];+ }+ });+ }];+ } else {+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];+ [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {+ dispatch_async(dispatch_get_main_queue(), ^{+ if (settings.authorizationStatus != UNAuthorizationStatusAuthorized) {+ self.receiveNotifEnabled = NO;+ [defaults setBool:NO forKey:@"receive_notif_enabled"];+ [defaults synchronize];+ sender.on = NO;++ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Enable in Settings"+ message:@"Notifications are disabled. Please enable them in the Settings app."+ preferredStyle:UIAlertControllerStyleAlert];+ [alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];+ [self presentViewController:alert animated:YES completion:nil];+ } else {+ NSLog(@"Notifications already authorized");+ }+ });+ }];+ }} else {NSLog(@"Receive Notifications on This Device turned OFF");- [[UIApplication sharedApplication] unregisterForRemoteNotifications];+ // Clear any pending notifications when turning off+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];+ [center removeAllPendingNotificationRequests];+ [center removeAllDeliveredNotifications];}}@@ -207,17 +272,17 @@- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {if (section == 0) {- NSInteger baseRows = 10; // Increased by 1 for the new toggle+ NSInteger baseRows = 10;if (self.useOwnServerEnabled && self.isEmailServerSectionExpanded) {- baseRows += 2; // Add Server Address and Test own server+ baseRows += 2;}if (self.isPresetsSectionExpanded) {NSArray *presetKeys = [[[NSUserDefaults standardUserDefaults] objectForKey:@"yolo_presets"] allKeys];- baseRows += presetKeys.count + 1; // Preset options + "Add Preset" row+ baseRows += presetKeys.count + 1;}return baseRows;} else if (section == 1) {- return [[NSUserDefaults standardUserDefaults] boolForKey:@"isSubscribed"] ? 0 : 1; // Upgrade button+ return [[NSUserDefaults standardUserDefaults] boolForKey:@"isSubscribed"] ? 0 : 1;}return 0;}@@ -229,7 +294,6 @@cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;}- // Reset cell propertiescell.backgroundColor = [UIColor secondarySystemBackgroundColor];cell.textLabel.textColor = [UIColor labelColor];cell.detailTextLabel.textColor = [UIColor secondaryLabelColor];@@ -424,7 +488,6 @@if (!isPremium) {[self showPremiumRequiredAlert];}- // Send Notifications - handled by switch} else if (indexPath.row == 6 + offset) {// Receive Notifications - handled by switch} else if (indexPath.row == 7 + offset) {