Skip to content

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

clean

roryclearb36e64285726
diff --git a/ios/clearcam/FileServer.h b/ios/clearcam/FileServer.h
index 625b6fb..f6620fe 100644
--- a/ios/clearcam/FileServer.h
+++ b/ios/clearcam/FileServer.h
@@ -18,7 +18,7 @@
body:(id)body
completionHandler:(void (^)(NSData *data, NSHTTPURLResponse *response, NSError *error))completion;
+ (void)sendDeviceTokenToServerWithCompletion:(void (^)(BOOL success))completion;
-+ (void)sendDeleteDeviceTokenToServerWithCompletion:(void (^)(BOOL success))completion;
++ (void)sendDeviceTokenToServerWithDelete:(BOOL)deleteToken completion:(void (^)(BOOL success))completion;
@property (nonatomic, assign) NSInteger segment_length;
@property (nonatomic, strong) NSDate *last_req_time;
@property (nonatomic, strong) PortScanner *scanner;
diff --git a/ios/clearcam/FileServer.m b/ios/clearcam/FileServer.m
index 7cd4a0b..be5a42e 100644
--- a/ios/clearcam/FileServer.m
+++ b/ios/clearcam/FileServer.m
@@ -704,7 +704,7 @@
return framesForURL;
}
-+ (void)sendDeviceTokenToServerWithCompletion:(void (^)(BOOL success))completion {
++ (void)sendDeviceTokenToServerWithDelete:(BOOL)deleteToken completion:(void (^)(BOOL success))completion {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *deviceToken = [defaults stringForKey:@"device_token"];
if (!deviceToken || deviceToken.length == 0) {
@@ -716,7 +716,10 @@
if (completion) completion(NO);
return;
}
- [FileServer performPostRequestWithURL:@"https://rors.ai/add_device"
+
+ NSString *endpoint = deleteToken ? @"https://rors.ai/delete_device" : @"https://rors.ai/add_device";
+
+ [FileServer performPostRequestWithURL:endpoint
method:@"POST"
contentType:@"application/json"
body:@{@"device_token": deviceToken, @"session_token": sessionToken}
@@ -726,26 +729,8 @@
}];
}
-+ (void)sendDeleteDeviceTokenToServerWithCompletion:(void (^)(BOOL success))completion {
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- NSString *deviceToken = [defaults stringForKey:@"device_token"];
- if (!deviceToken || deviceToken.length == 0) {
- if (completion) completion(NO);
- return;
- }
- NSString *sessionToken = [[StoreManager sharedInstance] retrieveSessionTokenFromKeychain];
- if (!sessionToken || sessionToken.length == 0) {
- if (completion) completion(NO);
- return;
- }
- [FileServer performPostRequestWithURL:@"https://rors.ai/delete_device"
- method:@"POST"
- contentType:@"application/json"
- body:@{@"device_token": deviceToken, @"session_token": sessionToken}
- completionHandler:^(NSData *data, NSHTTPURLResponse *response, NSError *error) {
- BOOL success = (error == nil && response.statusCode >= 200 && response.statusCode < 300);
- if (completion) completion(success);
- }];
++ (void)sendDeviceTokenToServerWithCompletion:(void (^)(BOOL success))completion {
+ [self sendDeviceTokenToServerWithDelete:NO completion:completion];
}
+ (void)performPostRequestWithURL:(NSString *)urlString
diff --git a/ios/clearcam/SettingsViewController.m b/ios/clearcam/SettingsViewController.m
index 9d6f327..d681a41 100644
--- a/ios/clearcam/SettingsViewController.m
+++ b/ios/clearcam/SettingsViewController.m
@@ -364,13 +364,10 @@
});
}];
} else {
- // Clear any pending notifications when turning off
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center removeAllPendingNotificationRequests];
[center removeAllDeliveredNotifications];
-
- // Delete device token from server with completion
- [FileServer sendDeleteDeviceTokenToServerWithCompletion:^(BOOL success) {
+ [FileServer sendDeviceTokenToServerWithDelete:YES completion:^(BOOL success) {
dispatch_async(dispatch_get_main_queue(), ^{
if (success) {
self.receiveNotifEnabled = NO;