Add object detection, tracking, mobile notifications, and search to any security camera.
new session check thing
rorycleara6f799ef45af
diff --git a/clearcam/SettingsViewController.m b/clearcam/SettingsViewController.mindex 86da046..99cea0d 100644--- a/clearcam/SettingsViewController.m+++ b/clearcam/SettingsViewController.m@@ -35,13 +35,11 @@[super viewDidLoad];self.view.backgroundColor = [UIColor systemBackgroundColor];self.title = @"Settings";- if (![[NSUserDefaults standardUserDefaults] boolForKey:@"isSubscribed"] || ![[NSDate date] compare:[[NSUserDefaults standardUserDefaults] objectForKey:@"expiry"]] || [[NSDate date] compare:[[NSUserDefaults standardUserDefaults] objectForKey:@"expiry"]] == NSOrderedDescending) {- [[StoreManager sharedInstance] verifySubscriptionWithCompletion:^(BOOL isActive, NSDate *expiryDate) {- dispatch_async(dispatch_get_main_queue(), ^{- [self.tableView reloadData];- });- }];- }+ [[StoreManager sharedInstance] verifySubscriptionWithCompletionIfSubbed:^(BOOL isActive, NSDate *expiryDate) {+ dispatch_async(dispatch_get_main_queue(), ^{+ [self.tableView reloadData];+ });+ }];// Register for subscription status change notifications[[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(subscriptionStatusDidChange:)diff --git a/clearcam/StoreManager.h b/clearcam/StoreManager.hindex a3b8716..e49e52b 100644--- a/clearcam/StoreManager.h+++ b/clearcam/StoreManager.h@@ -12,6 +12,7 @@ extern NSString *const StoreManagerSubscriptionStatusDidChangeNotification;- (void)fetchAndPurchaseProductWithCompletion:(void (^)(BOOL success, NSError * _Nullable error))completion;- (void)verifySubscriptionWithCompletion:(void (^)(BOOL isActive, NSDate * _Nullable expiryDate))completion;+- (void)verifySubscriptionWithCompletionIfSubbed:(void (^)(BOOL isActive, NSDate * _Nullable expiryDate))completion;- (NSString *)retrieveSessionTokenFromKeychain;- (void)getPremiumProductInfo:(void (^)(SKProduct * _Nullable product, NSError * _Nullable error))completion;- (void)restorePurchases;diff --git a/clearcam/StoreManager.m b/clearcam/StoreManager.mindex be34776..fefcf07 100644--- a/clearcam/StoreManager.m+++ b/clearcam/StoreManager.m@@ -64,10 +64,10 @@ NSString *const StoreManagerSubscriptionStatusDidChangeNotification = @"StoreMan}return;}-+// Store the completion handlerself.productInfoCompletionHandler = completion;-+// Fetch product info from App StoreNSSet *productIdentifiers = [NSSet setWithObject:@"monthly.premium"]; // Your product IDself.productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];@@ -78,7 +78,7 @@ NSString *const StoreManagerSubscriptionStatusDidChangeNotification = @"StoreMan#pragma mark - SKProductsRequestDelegate- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {- NSLog(@"Received product response.");+ NSLog(@"Received product response.");if (response.products.count > 0) {self.premiumProduct = response.products.firstObject;if (self.productInfoCompletionHandler) {@@ -90,25 +90,25 @@ NSString *const StoreManagerSubscriptionStatusDidChangeNotification = @"StoreMan} else {NSError *error = [NSError errorWithDomain:@"StoreManagerError" code:101 userInfo:@{NSLocalizedDescriptionKey: @"No products found."}];if (self.productInfoCompletionHandler) {- dispatch_async(dispatch_get_main_queue(), ^{+ dispatch_async(dispatch_get_main_queue(), ^{self.productInfoCompletionHandler(nil, error);self.productInfoCompletionHandler = nil;- });+ });}}- self.productsRequest.delegate = nil;- self.productsRequest = nil;+ self.productsRequest.delegate = nil;+ self.productsRequest = nil;}- (void)request:(SKRequest *)request didFailWithError:(NSError *)error {- if (self.productInfoCompletionHandler) {- dispatch_async(dispatch_get_main_queue(), ^{- self.productInfoCompletionHandler(nil, error);- self.productInfoCompletionHandler = nil; // Clear the handler- });- }- self.productsRequest.delegate = nil;- self.productsRequest = nil;+ if (self.productInfoCompletionHandler) {+ dispatch_async(dispatch_get_main_queue(), ^{+ self.productInfoCompletionHandler(nil, error);+ self.productInfoCompletionHandler = nil; // Clear the handler+ });+ }+ self.productsRequest.delegate = nil;+ self.productsRequest = nil;}#pragma mark - Purchase Product@@ -150,8 +150,8 @@ NSString *const StoreManagerSubscriptionStatusDidChangeNotification = @"StoreManif (transaction.error.code != SKErrorPaymentCancelled) {dispatch_async(dispatch_get_main_queue(), ^{UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Purchase Failed"- message:transaction.error.localizedDescription- preferredStyle:UIAlertControllerStyleAlert];+ message:transaction.error.localizedDescription+ preferredStyle:UIAlertControllerStyleAlert];[alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;while (topController.presentedViewController) {@@ -169,8 +169,8 @@ NSString *const StoreManagerSubscriptionStatusDidChangeNotification = @"StoreManif (isActive) {[[NSNotificationCenter defaultCenter] postNotificationName:StoreManagerSubscriptionStatusDidChangeNotification object:nil];UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Purchases Restored"- message:@"Your previous purchases have been successfully restored."- preferredStyle:UIAlertControllerStyleAlert];+ message:@"Your previous purchases have been successfully restored."+ preferredStyle:UIAlertControllerStyleAlert];[alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;while (topController.presentedViewController) {@@ -183,8 +183,8 @@ NSString *const StoreManagerSubscriptionStatusDidChangeNotification = @"StoreMan}} else {UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"No Purchases Found"- message:@"No previous purchases were found to restore."- preferredStyle:UIAlertControllerStyleAlert];+ message:@"No previous purchases were found to restore."+ preferredStyle:UIAlertControllerStyleAlert];[alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;while (topController.presentedViewController) {@@ -216,8 +216,8 @@ NSString *const StoreManagerSubscriptionStatusDidChangeNotification = @"StoreMan- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error {dispatch_async(dispatch_get_main_queue(), ^{UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Restore Failed"- message:error.localizedDescription- preferredStyle:UIAlertControllerStyleAlert];+ message:error.localizedDescription+ preferredStyle:UIAlertControllerStyleAlert];[alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;while (topController.presentedViewController) {@@ -227,6 +227,25 @@ NSString *const StoreManagerSubscriptionStatusDidChangeNotification = @"StoreMan});}+- (void)verifySubscriptionWithCompletionIfSubbed:(void (^)(BOOL isActive, NSDate *expiryDate))completion {+ NSDate *expiry = [[NSUserDefaults standardUserDefaults] objectForKey:@"expiry"];+ BOOL isSubscribed = [[NSUserDefaults standardUserDefaults] boolForKey:@"isSubscribed"];+ BOOL sessionExpiredOrNow = !expiry || [expiry compare:[NSDate date]] != NSOrderedDescending;+ if (isSubscribed || [[NSDate date] timeIntervalSince1970] - [StoreManager sharedInstance].last_check_time > 120.0) {+ if (sessionExpiredOrNow) {+ [self verifySubscriptionWithCompletion:^(BOOL isActive, NSDate *expiryDate) {+ if (completion) {+ completion(isActive, expiryDate);+ }+ }];+ } else {+ if (completion) {+ completion(isSubscribed, expiry);+ }+ }+ }+}+- (void)verifySubscriptionWithCompletion:(void (^)(BOOL isActive, NSDate *expiryDate))completion {self.last_check_time = [[NSDate date] timeIntervalSince1970];static BOOL isRequestInProgress = NO;diff --git a/clearcam/ViewController.m b/clearcam/ViewController.mindex 2eaff9b..030ba3b 100644--- a/clearcam/ViewController.m+++ b/clearcam/ViewController.m@@ -1126,20 +1126,11 @@ NSMutableDictionary *classColorMap;[FileServer sharedInstance].segment_length = 60;}if([[NSUserDefaults standardUserDefaults] boolForKey:@"live_stream_internet_enabled"]) {- if ([[NSDate date] timeIntervalSince1970] - self.last_check_time > 5.0) {- self.last_check_time = [[NSDate date] timeIntervalSince1970];- NSDate *expiry = [[NSUserDefaults standardUserDefaults] objectForKey:@"expiry"];- BOOL isSubscribed = [[NSUserDefaults standardUserDefaults] boolForKey:@"isSubscribed"];- BOOL sessionExpiredOrNow = !expiry || [expiry compare:[NSDate date]] != NSOrderedDescending;- if(isSubscribed || [[NSDate date] timeIntervalSince1970] - [StoreManager sharedInstance].last_check_time > 120.0) { //check every 2 mins?- if (sessionExpiredOrNow) {- [[StoreManager sharedInstance] verifySubscriptionWithCompletion:^(BOOL isActive, NSDate *expiryDate) {- [self checkUploadLink];- }];- } else{- [self checkUploadLink];- }- }+ if ([[NSDate date] timeIntervalSince1970] - self.last_check_time > 5.0) {+ self.last_check_time = [[NSDate date] timeIntervalSince1970];+ [[StoreManager sharedInstance] verifySubscriptionWithCompletionIfSubbed:^(BOOL isActive, NSDate *expiryDate) {+ [self checkUploadLink];+ }];}}if (elapsedTime >= [FileServer sharedInstance].segment_length || (self.isStreaming && elapsedTime > 2.0)) {