Skip to content

Add object detection, tracking, mobile notifications, and search to any security camera.

start notifications

rorycleardcc0e4d49ad6
diff --git a/clearcam.xcodeproj/project.pbxproj b/clearcam.xcodeproj/project.pbxproj
index 1f54c58..a8c097c 100644
--- a/clearcam.xcodeproj/project.pbxproj
+++ b/clearcam.xcodeproj/project.pbxproj
@@ -161,11 +161,14 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
+ CODE_SIGN_ENTITLEMENTS = clearcam/clearcam.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = VLS9B5G7MH;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = clearcam/Info.plist;
+ INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES;
+ INFOPLIST_KEY_NSCameraUsageDescription = "We need access to your camera to take photos and videos.";
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UIMainStoryboardFile = Main;
@@ -189,11 +192,14 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
+ CODE_SIGN_ENTITLEMENTS = clearcam/clearcam.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = VLS9B5G7MH;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = clearcam/Info.plist;
+ INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES;
+ INFOPLIST_KEY_NSCameraUsageDescription = "We need access to your camera to take photos and videos.";
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UIMainStoryboardFile = Main;
diff --git a/clearcam/AppDelegate.m b/clearcam/AppDelegate.m
index e27b94f..e59b4a6 100644
--- a/clearcam/AppDelegate.m
+++ b/clearcam/AppDelegate.m
@@ -1,12 +1,87 @@
#import "AppDelegate.h"
+#import <UserNotifications/UserNotifications.h>
+
+@interface AppDelegate () <UNUserNotificationCenterDelegate>
-@interface AppDelegate ()
@end
@implementation AppDelegate
@synthesize persistentContainer = _persistentContainer;
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
+ center.delegate = self; // Set the delegate
+
+ [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge)
+ completionHandler:^(BOOL granted, NSError * _Nullable error) {
+ if (granted) {
+ NSLog(@"Notification permission granted.");
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [[UIApplication sharedApplication] registerForRemoteNotifications];
+ });
+ } else {
+ NSLog(@"Notification permission denied: %@", error);
+ }
+ }];
+
+ return YES;
+}
+
+- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
+ NSString *token = [self stringFromDeviceToken:deviceToken];
+ NSLog(@"Device Token: %@", token);
+ // Send this token to your backend server.
+}
+
+- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
+ NSLog(@"Failed to register for remote notifications: %@", error);
+}
+
+- (NSString *)stringFromDeviceToken:(NSData *)deviceToken {
+ const char *data = [deviceToken bytes];
+ NSMutableString *token = [NSMutableString string];
+ for (NSUInteger i = 0; i < [deviceToken length]; i++) {
+ [token appendFormat:@"%02.2hhx", data[i]];
+ }
+ return [token copy];
+}
+
+// Handle incoming notifications while app is in the foreground
+- (void)userNotificationCenter:(UNUserNotificationCenter *)center
+ willPresentNotification:(UNNotification *)notification
+ withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
+ completionHandler(UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionBadge);
+}
+
+//Handle user interaction with notifications (tap)
+- (void)userNotificationCenter:(UNUserNotificationCenter *)center
+didReceiveNotificationResponse:(UNNotificationResponse *)response
+ withCompletionHandler:(void (^)(void))completionHandler {
+ // Handle notification tap here.
+ completionHandler();
+}
+
+// Handle silent notifications and notifications while app is in background/closed.
+- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
+ NSLog(@"Received remote notification: %@", userInfo);
+
+ if (userInfo[@"aps"][@"content-available"]) {
+ // Silent notification handling
+ NSLog(@"Received silent notification.");
+
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+ // Perform background tasks here.
+ sleep(5); // Simulate a background task. Replace with actual task.
+ completionHandler(UIBackgroundFetchResultNewData); // Or UIBackgroundFetchResultNoData
+ NSLog(@"Silent notification background task completed.");
+ });
+ } else {
+ // Regular notification handling.
+ completionHandler(UIBackgroundFetchResultNewData);
+ }
+}
+
- (NSPersistentContainer *)persistentContainer {
if (_persistentContainer == nil) {
_persistentContainer = [[NSPersistentContainer alloc] initWithName:@"SegmentsModel"];
@@ -19,4 +94,5 @@
}
return _persistentContainer;
}
+
@end
diff --git a/clearcam/Info.plist b/clearcam/Info.plist
index 12fbb02..551815b 100644
--- a/clearcam/Info.plist
+++ b/clearcam/Info.plist
@@ -2,71 +2,67 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
- <key>CFBundleDocumentTypes</key>
- <array>
- <dict>
- <key>CFBundleTypeName</key>
- <string>AES File</string>
- <key>LSItemContentTypes</key>
- <array>
- <string>com.clearcam.aesfile</string>
- </array>
- <key>CFBundleTypeExtensions</key>
- <array>
- <string>aes</string>
- </array>
- <key>LSHandlerRank</key>
- <string>Owner</string> <!-- Makes app the default handler -->
- </dict>
- </array>
-
- <key>UTExportedTypeDeclarations</key>
- <array>
- <dict>
- <key>UTTypeIdentifier</key>
- <string>com.clearcam.aesfile</string>
- <key>UTTypeDescription</key>
- <string>AES Encrypted File</string>
- <key>UTTypeConformsTo</key>
- <array>
- <string>public.data</string>
- </array>
- <key>UTTypeTagSpecification</key>
- <dict>
- <key>public.filename-extension</key>
- <array>
- <string>aes</string>
- </array>
- </dict>
- </dict>
- </array>
-
- <key>UIFileSharingEnabled</key>
- <true/>
- <key>LSSupportsOpeningDocumentsInPlace</key>
- <true/>
- <key>NSCameraUsageDescription</key>
- <string>We need access to your camera to take photos and videos.</string>
-
- <key>UIApplicationSceneManifest</key>
- <dict>
- <key>UIApplicationSupportsMultipleScenes</key>
- <false/>
- <key>UISceneConfigurations</key>
- <dict>
- <key>UIWindowSceneSessionRoleApplication</key>
- <array>
- <dict>
- <key>UISceneConfigurationName</key>
- <string>Default Configuration</string>
- <key>UISceneDelegateClassName</key>
- <string>SceneDelegate</string>
- <key>UISceneStoryboardFile</key>
- <string>Main</string>
- </dict>
- </array>
- </dict>
- </dict>
+ <key>CFBundleDocumentTypes</key>
+ <array>
+ <dict>
+ <key>CFBundleTypeExtensions</key>
+ <array>
+ <string>aes</string>
+ </array>
+ <key>CFBundleTypeName</key>
+ <string>AES File</string>
+ <key>LSHandlerRank</key>
+ <string>Owner</string>
+ <key>LSItemContentTypes</key>
+ <array>
+ <string>com.clearcam.aesfile</string>
+ </array>
+ </dict>
+ </array>
+ <key>UIApplicationSceneManifest</key>
+ <dict>
+ <key>UIApplicationSupportsMultipleScenes</key>
+ <false/>
+ <key>UISceneConfigurations</key>
+ <dict>
+ <key>UIWindowSceneSessionRoleApplication</key>
+ <array>
+ <dict>
+ <key>UISceneConfigurationName</key>
+ <string>Default Configuration</string>
+ <key>UISceneDelegateClassName</key>
+ <string>SceneDelegate</string>
+ <key>UISceneStoryboardFile</key>
+ <string>Main</string>
+ </dict>
+ </array>
+ </dict>
+ </dict>
+ <key>UIBackgroundModes</key>
+ <array>
+ <string>remote-notification</string>
+ </array>
+ <key>UIFileSharingEnabled</key>
+ <true/>
+ <key>UTExportedTypeDeclarations</key>
+ <array>
+ <dict>
+ <key>UTTypeConformsTo</key>
+ <array>
+ <string>public.data</string>
+ </array>
+ <key>UTTypeDescription</key>
+ <string>AES Encrypted File</string>
+ <key>UTTypeIdentifier</key>
+ <string>com.clearcam.aesfile</string>
+ <key>UTTypeTagSpecification</key>
+ <dict>
+ <key>public.filename-extension</key>
+ <array>
+ <string>aes</string>
+ </array>
+ </dict>
+ </dict>
+ </array>
</dict>
</plist>
-
diff --git a/clearcam/clearcam.entitlements b/clearcam/clearcam.entitlements
new file mode 100644
index 0000000..903def2
--- /dev/null
+++ b/clearcam/clearcam.entitlements
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>aps-environment</key>
+ <string>development</string>
+</dict>
+</plist>