Add object detection, tracking, mobile notifications, and search to any security camera.
load when buying
roryclear05b3d2179d36
diff --git a/clearcam/SettingsViewController.m b/clearcam/SettingsViewController.mindex fa9b7ad..88b7c6d 100644--- a/clearcam/SettingsViewController.m+++ b/clearcam/SettingsViewController.m@@ -918,8 +918,48 @@- (void)handleUpgradeTap {- [self dismissUpgradePopup];- [[StoreManager sharedInstance] fetchAndPurchaseProduct];+ // Create and show a loading spinner+ UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];+ spinner.translatesAutoresizingMaskIntoConstraints = NO;+ spinner.color = [UIColor whiteColor];+ UIView *overlay = [self.view viewWithTag:999];+ [overlay addSubview:spinner];++ // Center the spinner in the overlay+ [NSLayoutConstraint activateConstraints:@[+ [spinner.centerXAnchor constraintEqualToAnchor:overlay.centerXAnchor],+ [spinner.centerYAnchor constraintEqualToAnchor:overlay.centerYAnchor]+ ]];++ [spinner startAnimating];++ // Disable user interaction on the overlay to prevent multiple taps+ overlay.userInteractionEnabled = NO;++ // Fetch and initiate the purchase+ [[StoreManager sharedInstance] fetchAndPurchaseProductWithCompletion:^(BOOL success, NSError * _Nullable error) {+ dispatch_async(dispatch_get_main_queue(), ^{+ // Stop the spinner and re-enable interaction+ [spinner stopAnimating];+ [spinner removeFromSuperview];+ overlay.userInteractionEnabled = YES;++ // Dismiss the upgrade popup+ [self dismissUpgradePopup];++ if (!success && error) {+ // Show error alert if purchase failed+ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Purchase Failed"+ message:error.localizedDescription+ preferredStyle:UIAlertControllerStyleAlert];+ [alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];+ [self presentViewController:alert animated:YES completion:nil];+ }++ // Reload table to reflect subscription status+ [self.tableView reloadData];+ });+ }];}- (void)dismissUpgradePopup {diff --git a/clearcam/StoreManager.h b/clearcam/StoreManager.hindex e67a505..a3b8716 100644--- a/clearcam/StoreManager.h+++ b/clearcam/StoreManager.h@@ -10,7 +10,7 @@ extern NSString *const StoreManagerSubscriptionStatusDidChangeNotification;+ (instancetype)sharedInstance;-- (void)fetchAndPurchaseProduct;+- (void)fetchAndPurchaseProductWithCompletion:(void (^)(BOOL success, NSError * _Nullable error))completion;- (void)verifySubscriptionWithCompletion:(void (^)(BOOL isActive, NSDate * _Nullable expiryDate))completion;- (NSString *)retrieveSessionTokenFromKeychain;- (void)getPremiumProductInfo:(void (^)(SKProduct * _Nullable product, NSError * _Nullable error))completion;diff --git a/clearcam/StoreManager.m b/clearcam/StoreManager.mindex 06815fc..be34776 100644--- a/clearcam/StoreManager.m+++ b/clearcam/StoreManager.m@@ -9,6 +9,8 @@ NSString *const StoreManagerSubscriptionStatusDidChangeNotification = @"StoreMan@property (nonatomic, strong) SKProductsRequest *productsRequest;@property (nonatomic, strong) SKProduct *premiumProduct;@property (nonatomic, strong) void (^productInfoCompletionHandler)(SKProduct * _Nullable product, NSError * _Nullable error); // Store completion handler for fetching info+@property (nonatomic, copy) void (^purchaseCompletionHandler)(BOOL success, NSError * _Nullable error);+// Implement SKPaymentTransactionObserver method to handle transaction updates- (void)getPremiumProductInfo:(void (^)(SKProduct * _Nullable product, NSError * _Nullable error))completion;@end@@ -18,11 +20,12 @@ NSString *const StoreManagerSubscriptionStatusDidChangeNotification = @"StoreMan[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];}-+ (instancetype)sharedInstance {++ (StoreManager *)sharedInstance {static StoreManager *sharedInstance = nil;static dispatch_once_t onceToken;dispatch_once(&onceToken, ^{- sharedInstance = [[self alloc] init];+ sharedInstance = [[StoreManager alloc] init];+ [[SKPaymentQueue defaultQueue] addTransactionObserver:sharedInstance];});return sharedInstance;}@@ -36,28 +39,22 @@ NSString *const StoreManagerSubscriptionStatusDidChangeNotification = @"StoreManreturn self;}-- (void)fetchAndPurchaseProduct {- if (self.premiumProduct) {- [self purchaseProduct:self.premiumProduct];- } else {- [self getPremiumProductInfo:^(SKProduct * _Nullable product, NSError * _Nullable error) {- dispatch_async(dispatch_get_main_queue(), ^{- if (product) {- [self purchaseProduct:product];- } else {- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Error"- message:@"Could not retrieve product information. Please try again later."- preferredStyle:UIAlertControllerStyleAlert];- [alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];- UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;- while (topController.presentedViewController) {- topController = topController.presentedViewController;- }- [topController presentViewController:alert animated:YES completion:nil];- }- });- }];- }+- (void)fetchAndPurchaseProductWithCompletion:(void (^)(BOOL success, NSError * _Nullable error))completion {+ [self getPremiumProductInfo:^(SKProduct * _Nullable product, NSError * _Nullable error) {+ if (!product) {+ if (completion) {+ completion(NO, error ?: [NSError errorWithDomain:@"StoreManager" code:-1 userInfo:@{NSLocalizedDescriptionKey: @"Failed to fetch product information"}]);+ }+ return;+ }++ // Initiate the purchase+ SKPayment *payment = [SKPayment paymentWithProduct:product];+ [[SKPaymentQueue defaultQueue] addPayment:payment];++ // Store the completion handler to call it when the transaction finishes+ self.purchaseCompletionHandler = completion;+ }];}- (void)getPremiumProductInfo:(void (^)(SKProduct * _Nullable product, NSError * _Nullable error))completion {@@ -128,17 +125,28 @@ NSString *const StoreManagerSubscriptionStatusDidChangeNotification = @"StoreMan- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray<SKPaymentTransaction *> *)transactions {for (SKPaymentTransaction *transaction in transactions) {switch (transaction.transactionState) {- case SKPaymentTransactionStatePurchased:+ case SKPaymentTransactionStatePurchased: {[[SKPaymentQueue defaultQueue] finishTransaction:transaction];[self verifySubscriptionWithCompletion:^(BOOL isActive, NSDate *expiryDate) {if (isActive) {[[NSNotificationCenter defaultCenter] postNotificationName:StoreManagerSubscriptionStatusDidChangeNotification object:nil];+ if (self.purchaseCompletionHandler) {+ self.purchaseCompletionHandler(YES, nil);+ self.purchaseCompletionHandler = nil;+ }+ } else if (self.purchaseCompletionHandler) {+ self.purchaseCompletionHandler(NO, [NSError errorWithDomain:@"StoreManager" code:-1 userInfo:@{NSLocalizedDescriptionKey: @"Subscription verification failed"}]);+ self.purchaseCompletionHandler = nil;}}];break;-- case SKPaymentTransactionStateFailed:+ }+ case SKPaymentTransactionStateFailed: {[[SKPaymentQueue defaultQueue] finishTransaction:transaction];+ if (self.purchaseCompletionHandler) {+ self.purchaseCompletionHandler(NO, transaction.error);+ self.purchaseCompletionHandler = nil;+ }if (transaction.error.code != SKErrorPaymentCancelled) {dispatch_async(dispatch_get_main_queue(), ^{UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Purchase Failed"@@ -153,8 +161,8 @@ NSString *const StoreManagerSubscriptionStatusDidChangeNotification = @"StoreMan});}break;-- case SKPaymentTransactionStateRestored:+ }+ case SKPaymentTransactionStateRestored: {[[SKPaymentQueue defaultQueue] finishTransaction:transaction];[self verifySubscriptionWithCompletion:^(BOOL isActive, NSDate *expiryDate) {dispatch_async(dispatch_get_main_queue(), ^{@@ -169,6 +177,10 @@ NSString *const StoreManagerSubscriptionStatusDidChangeNotification = @"StoreMantopController = topController.presentedViewController;}[topController presentViewController:alert animated:YES completion:nil];+ if (self.purchaseCompletionHandler) {+ self.purchaseCompletionHandler(YES, nil);+ self.purchaseCompletionHandler = nil;+ }} else {UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"No Purchases Found"message:@"No previous purchases were found to restore."@@ -179,11 +191,18 @@ NSString *const StoreManagerSubscriptionStatusDidChangeNotification = @"StoreMantopController = topController.presentedViewController;}[topController presentViewController:alert animated:YES completion:nil];+ if (self.purchaseCompletionHandler) {+ self.purchaseCompletionHandler(NO, [NSError errorWithDomain:@"StoreManager" code:-1 userInfo:@{NSLocalizedDescriptionKey: @"No valid subscriptions found"}]);+ self.purchaseCompletionHandler = nil;+ }}});}];break;-+ }+ case SKPaymentTransactionStatePurchasing:+ // No action needed while purchasing+ break;default:break;}