Skip to content

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

clean a bit

roryclear4b28283d631b
diff --git a/clearcam/AppDelegate.m b/clearcam/AppDelegate.m
index 99cb701..8a9c8c8 100644
--- a/clearcam/AppDelegate.m
+++ b/clearcam/AppDelegate.m
@@ -96,7 +96,7 @@
// Save token to NSUserDefaults
[[NSUserDefaults standardUserDefaults] setObject:token forKey:@"device_token"];
[[NSUserDefaults standardUserDefaults] synchronize];
- [self sendDeviceTokenToServer];
+ [FileServer sendDeviceTokenToServer];
}
@@ -119,39 +119,6 @@
}
}
-- (void)sendDeviceTokenToServer { //todo duplicate!!
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- NSString *deviceToken = [defaults stringForKey:@"device_token"];
-
- if (!deviceToken || deviceToken.length == 0) {
- NSLog(@"No device token found, skipping API call.");
- return;
- }
-
- // Retrieve session token from Keychain
- NSString *sessionToken = [[StoreManager sharedInstance] retrieveSessionTokenFromKeychain];
- if (!sessionToken || sessionToken.length == 0) {
- NSLog(@"No session token found in Keychain. Skipping API call.");
- return;
- }
-
- [FileServer performPostRequestWithURL:@"https://rors.ai/add_device"
- method:@"POST"
- contentType:@"application/json"
- body:@{@"device_token": deviceToken, @"session_token": sessionToken}
- completionHandler:^(NSData *data, NSHTTPURLResponse *response, NSError *error) {
- if (error) {
- NSLog(@"Error sending device token: %@", error.localizedDescription);
- return;
- }
- if (response.statusCode == 200) {
- NSLog(@"Device token successfully sent to server");
- } else {
- NSLog(@"Failed to send device token, server responded with status code: %ld", (long)response.statusCode);
- }
- }];
-}
-
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler {
diff --git a/clearcam/FileServer.h b/clearcam/FileServer.h
index d3454d3..670abee 100644
--- a/clearcam/FileServer.h
+++ b/clearcam/FileServer.h
@@ -17,6 +17,7 @@
contentType:(NSString *)contentType
body:(id)body
completionHandler:(void (^)(NSData *data, NSHTTPURLResponse *response, NSError *error))completion;
++ (void)sendDeviceTokenToServer;
@property (nonatomic, assign) NSInteger segment_length;
@property (nonatomic, strong) NSDate *last_req_time;
@property (nonatomic, strong) PortScanner *scanner;
diff --git a/clearcam/FileServer.m b/clearcam/FileServer.m
index f3ed1c5..43b1ac9 100644
--- a/clearcam/FileServer.m
+++ b/clearcam/FileServer.m
@@ -10,6 +10,7 @@
#import "SettingsManager.h"
#import "PortScanner.h"
#import "AppDelegate.h"
+#import "StoreManager.h"
#import <CoreData/CoreData.h>
#import "SecretManager.h"
@@ -892,6 +893,36 @@
return framesForURL;
}
++ (void)sendDeviceTokenToServer {
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+ NSString *deviceToken = [defaults stringForKey:@"device_token"];
+ if (!deviceToken || deviceToken.length == 0) {
+ NSLog(@"No device token found, skipping API call.");
+ return;
+ }
+ NSString *sessionToken = [[StoreManager sharedInstance] retrieveSessionTokenFromKeychain];
+ if (!sessionToken || sessionToken.length == 0) {
+ NSLog(@"No session token found in Keychain. Skipping API call.");
+ return;
+ }
+
+ [FileServer performPostRequestWithURL:@"https://rors.ai/add_device"
+ method:@"POST"
+ contentType:@"application/json"
+ body:@{@"device_token": deviceToken, @"session_token": sessionToken}
+ completionHandler:^(NSData *data, NSHTTPURLResponse *response, NSError *error) {
+ if (error) {
+ NSLog(@"Error sending device token: %@", error.localizedDescription);
+ return;
+ }
+ if (response.statusCode == 200) {
+ NSLog(@"Device token successfully sent to server");
+ } else {
+ NSLog(@"Failed to send device token, server responded with status code: %ld", (long)response.statusCode);
+ }
+ }];
+}
+
+ (void)performPostRequestWithURL:(NSString *)urlString
method:(NSString *)method
contentType:(NSString *)contentType
diff --git a/clearcam/SettingsViewController.m b/clearcam/SettingsViewController.m
index e16fb31..bce8367 100644
--- a/clearcam/SettingsViewController.m
+++ b/clearcam/SettingsViewController.m
@@ -192,7 +192,7 @@
dispatch_async(dispatch_get_main_queue(), ^{
if (settings.authorizationStatus == UNAuthorizationStatusAuthorized) {
NSLog(@"Notifications already authorized, sending token...");
- [self sendDeviceTokenToServer]; // Send token when toggled ON
+ [FileServer sendDeviceTokenToServer]; // Send token when toggled ON
} else if (!hasRequestedPermission) {
NSLog(@"Requesting permission for notifications...");
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge)
@@ -204,7 +204,7 @@
[defaults setBool:YES forKey:@"hasRequestedNotificationPermission"];
[defaults synchronize];
- [self sendDeviceTokenToServer]; // Send token after granting permission
+ [FileServer sendDeviceTokenToServer]; // Send token after granting permission
} else {
NSLog(@"Notification permission denied: %@", error);
self.receiveNotifEnabled = NO;
@@ -247,39 +247,6 @@
}
}
-- (void)sendDeviceTokenToServer {
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- NSString *deviceToken = [defaults stringForKey:@"device_token"];
-
- if (!deviceToken || deviceToken.length == 0) {
- NSLog(@"No device token found, skipping API call.");
- return;
- }
-
- // Retrieve session token from Keychain
- NSString *sessionToken = [[StoreManager sharedInstance] retrieveSessionTokenFromKeychain];
- if (!sessionToken || sessionToken.length == 0) {
- NSLog(@"No session token found in Keychain. Skipping API call.");
- return;
- }
-
- [FileServer performPostRequestWithURL:@"https://rors.ai/add_device"
- method:@"POST"
- contentType:@"application/json"
- body:@{@"device_token": deviceToken, @"session_token": sessionToken}
- completionHandler:^(NSData *data, NSHTTPURLResponse *response, NSError *error) {
- if (error) {
- NSLog(@"Error sending device token: %@", error.localizedDescription);
- return;
- }
- if (response.statusCode == 200) {
- NSLog(@"Device token successfully sent to server");
- } else {
- NSLog(@"Failed to send device token, server responded with status code: %ld", (long)response.statusCode);
- }
- }];
-}
-
- (void)deleteDeviceTokenFromServer {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *deviceToken = [defaults stringForKey:@"device_token"];