Skip to content

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

online status (#72)

Rory Clearc42a0d83dbd0
diff --git a/ios/clearcam/GalleryViewController.h b/ios/clearcam/GalleryViewController.h
index a5af401..2834456 100644
--- a/ios/clearcam/GalleryViewController.h
+++ b/ios/clearcam/GalleryViewController.h
@@ -9,6 +9,9 @@
@property (nonatomic, strong) UIButton *cameraButton;
@property (nonatomic, strong) UIButton *settingsButton;
@property (nonatomic, strong) UIStackView *headerStackView;
+@property (nonatomic, strong) UIView *statusDot;
+@property (nonatomic, strong) UILabel *statusLabel;
+@property (nonatomic, strong) NSTimer *statusTimer;
- (void)getEvents;
@end
diff --git a/ios/clearcam/GalleryViewController.m b/ios/clearcam/GalleryViewController.m
index 0c4d5e0..a7b13ad 100644
--- a/ios/clearcam/GalleryViewController.m
+++ b/ios/clearcam/GalleryViewController.m
@@ -44,7 +44,6 @@
self.menuButton.tintColor = [UIColor systemGrayColor];
self.menuButton.transform = CGAffineTransformMakeRotation(M_PI_2);
[self.contentView addSubview:self.menuButton];
-
self.thumbnailView.translatesAutoresizingMaskIntoConstraints = NO;
self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
self.menuButton.translatesAutoresizingMaskIntoConstraints = NO;
@@ -96,19 +95,16 @@
[self.navigationController setNavigationBarHidden:YES animated:NO];
self.view.backgroundColor = [UIColor systemBackgroundColor];
- // Create header view
self.headerView = [[UIView alloc] init];
self.headerView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:self.headerView];
- // Camera button
self.cameraButton = [UIButton buttonWithType:UIButtonTypeSystem];
[self.cameraButton setImage:[UIImage systemImageNamed:@"camera.fill"] forState:UIControlStateNormal];
self.cameraButton.tintColor = [[UIColor grayColor] colorWithAlphaComponent:0.9];
[self.cameraButton addTarget:self action:@selector(cameraTapped) forControlEvents:UIControlEventTouchUpInside];
self.cameraButton.translatesAutoresizingMaskIntoConstraints = NO;
- // App icon
NSArray *iconFiles = [[[NSBundle mainBundle] infoDictionary] valueForKeyPath:@"CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles"];
NSString *iconName = [iconFiles lastObject];
UIImageView *appIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:iconName]];
@@ -119,14 +115,12 @@
[appIconView.widthAnchor constraintEqualToConstant:24].active = YES;
[appIconView.heightAnchor constraintEqualToConstant:24].active = YES;
- // Settings button
self.settingsButton = [UIButton buttonWithType:UIButtonTypeSystem];
[self.settingsButton setImage:[UIImage systemImageNamed:@"gearshape.fill"] forState:UIControlStateNormal];
self.settingsButton.tintColor = [[UIColor grayColor] colorWithAlphaComponent:0.9];
[self.settingsButton addTarget:self action:@selector(settingsTapped) forControlEvents:UIControlEventTouchUpInside];
self.settingsButton.translatesAutoresizingMaskIntoConstraints = NO;
- // IP label
self.ipLabel = [[UILabel alloc] init];
self.ipLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
self.ipLabel.textColor = [UIColor secondaryLabelColor];
@@ -141,7 +135,6 @@
titleStack.spacing = 16;
titleStack.translatesAutoresizingMaskIntoConstraints = NO;
- // Vertical stack for entire header
UIStackView *headerStack = [[UIStackView alloc] initWithArrangedSubviews:@[titleStack, self.ipLabel]];
headerStack.axis = UILayoutConstraintAxisVertical;
headerStack.spacing = 8;
@@ -168,6 +161,36 @@
self.tabController.view.translatesAutoresizingMaskIntoConstraints = NO;
[self.tabController didMoveToParentViewController:self];
+ self.statusDot = [[UIView alloc] init];
+ self.statusDot.translatesAutoresizingMaskIntoConstraints = NO;
+ self.statusDot.layer.cornerRadius = 6;
+ self.statusDot.layer.masksToBounds = YES;
+ [self.statusDot.widthAnchor constraintEqualToConstant:12].active = YES;
+ [self.statusDot.heightAnchor constraintEqualToConstant:12].active = YES;
+
+ self.statusLabel = [[UILabel alloc] init];
+ self.statusLabel.translatesAutoresizingMaskIntoConstraints = NO;
+ self.statusLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
+ self.statusLabel.textColor = [UIColor secondaryLabelColor];
+
+ UIStackView *statusStack = [[UIStackView alloc] initWithArrangedSubviews:@[self.statusDot, self.statusLabel]];
+ statusStack.axis = UILayoutConstraintAxisHorizontal;
+ statusStack.spacing = 6;
+ statusStack.alignment = UIStackViewAlignmentCenter;
+ statusStack.translatesAutoresizingMaskIntoConstraints = NO;
+
+ [self.view addSubview:statusStack];
+
+ [NSLayoutConstraint activateConstraints:@[
+ [statusStack.topAnchor constraintEqualToAnchor:self.headerView.bottomAnchor constant:8],
+ [statusStack.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor],
+
+ [self.tabController.view.topAnchor constraintEqualToAnchor:statusStack.bottomAnchor constant:4],
+ [self.tabController.view.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
+ [self.tabController.view.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
+ [self.tabController.view.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor]
+ ]];
+
[NSLayoutConstraint activateConstraints:@[
[self.headerView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor],
[self.headerView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
@@ -204,15 +227,31 @@
self.loadedFilenames = [NSMutableSet set];
[self setupDownloadDirectory];
[self loadExistingVideos];
-
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(updateIPAddressLabel)
- name:@"DeviceIPAddressDidChangeNotification"
- object:nil];
-
- [self updateIPAddressLabel];
[self updateTableViewBackground];
[self setupRefreshTimer];
+
+ self.statusTimer = [NSTimer scheduledTimerWithTimeInterval:10.0
+ target:self
+ selector:@selector(updateInternetStatus)
+ userInfo:nil
+ repeats:YES];
+ [self updateInternetStatus];
+}
+
+- (void)updateInternetStatus {
+ [[StoreManager sharedInstance] checkInternetWithCompletion:^(BOOL hasInternet) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if (hasInternet) {
+ self.statusDot.backgroundColor = [UIColor systemGreenColor];
+ self.statusLabel.text = NSLocalizedString(@"online", @"online status");
+ self.statusLabel.textColor = [UIColor systemGrayColor];
+ } else {
+ self.statusDot.backgroundColor = [UIColor systemRedColor];
+ self.statusLabel.text = NSLocalizedString(@"offline", @"offline status");
+ self.statusLabel.textColor = [UIColor systemGrayColor];
+ }
+ });
+ }];
}
- (void)viewWillAppear:(BOOL)animated {
@@ -220,25 +259,6 @@
[self.navigationController setNavigationBarHidden:YES animated:NO];
}
-- (void)updateIPAddressLabel {
- BOOL streamViaWifiEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"stream_via_wifi_enabled"];
- NSString *ipAddress = [[NSUserDefaults standardUserDefaults] stringForKey:@"DeviceIPAddress"];
-
- if (streamViaWifiEnabled) {
- self.ipLabel.hidden = NO;
- self.ipLabel.text = (ipAddress.length > 0) ? [NSString stringWithFormat:NSLocalizedString(@"streaming_over_wifi", nil), ipAddress] : NSLocalizedString(@"waiting_for_ip", nil);
- self.mainStackViewTopToSafeAreaConstraint.active = NO;
- self.mainStackViewTopToIPLabelConstraint.active = YES;
- } else {
- self.ipLabel.hidden = YES;
- self.ipLabel.text = nil;
- self.mainStackViewTopToIPLabelConstraint.active = NO;
- self.mainStackViewTopToSafeAreaConstraint.active = YES;
- }
-
- [self.view layoutIfNeeded];
-}
-
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated];
@@ -247,6 +267,8 @@
- (void)dealloc {
[self.refreshTimer invalidate];
self.refreshTimer = nil;
+ [self.statusTimer invalidate];
+ self.statusTimer = nil;
}
- (void)setupRefreshTimer {
@@ -911,3 +933,4 @@
}
@end
+
diff --git a/ios/clearcam/SceneDelegate.m b/ios/clearcam/SceneDelegate.m
index d382c6d..5dd67c4 100644
--- a/ios/clearcam/SceneDelegate.m
+++ b/ios/clearcam/SceneDelegate.m
@@ -25,56 +25,36 @@ willConnectToSession:(UISceneSession *)session
self.window.rootViewController = loadingVC;
[self.window makeKeyAndVisible];
-
- // Check authentication status properly
[self verifyAuthentication];
}
- (void)verifyAuthentication {
- [self checkInternetWithCompletion:^(BOOL hasInternet) {
+ [[StoreManager sharedInstance] checkInternetWithCompletion:^(BOOL hasInternet) {
if (!hasInternet) {
dispatch_async(dispatch_get_main_queue(), ^{
[self switchToRootViewController:[[GalleryViewController alloc] init]];
});
return;
}
- //todo session only if logged out??
- [[StoreManager sharedInstance] verifySubscriptionWithCompletion:^(BOOL isActive, NSDate *expiryDate) {
- dispatch_async(dispatch_get_main_queue(), ^{
- UIViewController *rootVC;
-
- if (isActive) {
- rootVC = [[GalleryViewController alloc] init];
- } else {
- rootVC = [[LoginViewController alloc] init];
- [[StoreManager sharedInstance] clearSessionTokenFromKeychain];
- }
- [self switchToRootViewController:rootVC];
- });
- }];
+ [self attemptVerifySubscriptionWithRetry:2];
}];
}
-- (void)checkInternetWithCompletion:(void (^)(BOOL hasInternet))completion {
- NSURL *url = [NSURL URLWithString:@"https://rors.ai/ping"];
- NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
- cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
- timeoutInterval:3.0];
- request.HTTPMethod = @"HEAD";
- NSURLSessionDataTask *task = [[NSURLSession sharedSession]
- dataTaskWithRequest:request
- completionHandler:^(NSData * _Nullable data,
- NSURLResponse * _Nullable response,
- NSError * _Nullable error) {
- if (error) {
- completion(NO);
- return;
- }
- completion(response != nil);
+- (void)attemptVerifySubscriptionWithRetry:(NSInteger)remainingAttempts {
+ [[StoreManager sharedInstance] verifySubscriptionWithCompletion:^(BOOL isActive, NSDate *expiryDate) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if (isActive) {
+ [self switchToRootViewController:[[GalleryViewController alloc] init]];
+ } else if (remainingAttempts > 0) {
+ [self attemptVerifySubscriptionWithRetry:remainingAttempts - 1];
+ } else {
+ [self switchToRootViewController:[[LoginViewController alloc] init]];
+ }
+ });
}];
- [task resume];
}
+
- (void)switchToRootViewController:(UIViewController *)rootVC {
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootVC];
[UIView transitionWithView:self.window
diff --git a/ios/clearcam/StoreManager.h b/ios/clearcam/StoreManager.h
index 0b711e1..297b2df 100644
--- a/ios/clearcam/StoreManager.h
+++ b/ios/clearcam/StoreManager.h
@@ -26,6 +26,7 @@ extern NSString *const StoreManagerSubscriptionStatusDidChangeNotification;
- (void)showUpgradePopupInViewController:(UIViewController *)presentingVC;
- (void)showUpgradePopupInViewController:(UIViewController *)presentingVC
completion:(void (^)(BOOL success))completion;
+- (void)checkInternetWithCompletion:(void (^)(BOOL hasInternet))completion;
@end
diff --git a/ios/clearcam/StoreManager.m b/ios/clearcam/StoreManager.m
index 4bfc247..7ffe9b1 100644
--- a/ios/clearcam/StoreManager.m
+++ b/ios/clearcam/StoreManager.m
@@ -481,6 +481,26 @@ NSString *const StoreManagerSubscriptionStatusDidChangeNotification = @"StoreMan
[self verifySessionOrSubscription:YES completion:completion];
}
+- (void)checkInternetWithCompletion:(void (^)(BOOL hasInternet))completion {
+ NSURL *url = [NSURL URLWithString:@"https://rors.ai/ping"];
+ NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
+ cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
+ timeoutInterval:3.0];
+ request.HTTPMethod = @"HEAD";
+ NSURLSessionDataTask *task = [[NSURLSession sharedSession]
+ dataTaskWithRequest:request
+ completionHandler:^(NSData * _Nullable data,
+ NSURLResponse * _Nullable response,
+ NSError * _Nullable error) {
+ if (error) {
+ completion(NO);
+ return;
+ }
+ completion(response != nil);
+ }];
+ [task resume];
+}
+
- (void)verifySessionOrSubscription:(BOOL)checkSubscription
completion:(void (^)(BOOL isActive, NSDate *expiryDate))completion
{
diff --git a/ios/clearcam/en.lproj/Localizable.strings b/ios/clearcam/en.lproj/Localizable.strings
index 8a04f7f..b0c8e0a 100644
--- a/ios/clearcam/en.lproj/Localizable.strings
+++ b/ios/clearcam/en.lproj/Localizable.strings
@@ -3,7 +3,6 @@
"live"="Live";
"default_device_name" = "My Device";
"waiting_for_ip" = "Waiting for Wi-Fi...";
-"streaming_over_wifi" = "Streaming over local Wi-Fi at: %@";
"permission_denied" = "Permission Denied";
"notification_permission_denied" = "Notification permission was denied. You can enable it in Settings.";
"ok" = "OK";
@@ -90,6 +89,7 @@
"delete" = "Delete";
"cancel" = "Cancel";
"online" = "Online";
+"offline" = "Offline";
"experimental_features" = "Experimental Features";
"docs" = "Docs";
"app_name" = "Clearcam";
diff --git a/ios/clearcam/es.lproj/Localizable.strings b/ios/clearcam/es.lproj/Localizable.strings
index 00824ff..025530e 100644
--- a/ios/clearcam/es.lproj/Localizable.strings
+++ b/ios/clearcam/es.lproj/Localizable.strings
@@ -3,7 +3,6 @@
"live" = "En vivo";
"default_device_name" = "Mi dispositivo";
"waiting_for_ip" = "Esperando Wi-Fi...";
-"streaming_over_wifi" = "Transmitiendo por Wi-Fi local en: %@";
"permission_denied" = "Permiso denegado";
"notification_permission_denied" = "Permiso de notificaciones denegado. Actívalo en Ajustes.";
"ok" = "Aceptar";
@@ -90,6 +89,8 @@
"delete" = "Eliminar";
"cancel" = "Cancelar";
"online" = "En línea";
+"offline" = "Desconectado";
+
"experimental_features" = "Funciones experimentales";
"docs" = "Documentación";
"app_name" = "Clearcam";
diff --git a/ios/clearcam/hi.lproj/Localizable.strings b/ios/clearcam/hi.lproj/Localizable.strings
index a0700be..29a8a55 100644
--- a/ios/clearcam/hi.lproj/Localizable.strings
+++ b/ios/clearcam/hi.lproj/Localizable.strings
@@ -3,7 +3,6 @@
"live" = "लाइव";
"default_device_name" = "मेरा डिवाइस";
"waiting_for_ip" = "Wi-Fi का इंतज़ार कर रहे...";
-"streaming_over_wifi" = "स्थानीय Wi-Fi पर स्ट्रीमिंग: %@";
"permission_denied" = "अनुमति अस्वीकृत";
"notification_permission_denied" = "सूचना की अनुमति अस्वीकृत कर दी गई है। आप इसे सेटिंग्स में सक्षम कर सकते हैं।";
"ok" = "ठीक है";
@@ -90,6 +89,8 @@
"delete" = "हटाएं";
"cancel" = "रद्द करें";
"online" = "ऑनलाइन";
+"offline" = "ऑफ़लाइन";
+
"experimental_features" = "प्रायोगिक विशेषताएँ";
"docs" = "दस्तावेज़";
"app_name" = "Clearcam";
diff --git a/ios/clearcam/ja.lproj/Localizable.strings b/ios/clearcam/ja.lproj/Localizable.strings
index a5ce9ee..9e22ba3 100644
--- a/ios/clearcam/ja.lproj/Localizable.strings
+++ b/ios/clearcam/ja.lproj/Localizable.strings
@@ -3,7 +3,6 @@
"live" = "ライブ";
"default_device_name" = "マイデバイス";
"waiting_for_ip" = "Wi-Fiを待機中...";
-"streaming_over_wifi" = "ローカルWi-Fiでストリーミング中: %@";
"permission_denied" = "アクセス拒否されました";
"notification_permission_denied" = "通知許可が拒否されました。設定から有効にできます。";
"ok" = "OK";
@@ -90,6 +89,8 @@
"delete" = "削除";
"cancel" = "キャンセル";
"online" = "オンライン";
+"offline" = "オフライン";
+
"experimental_features" = "実験的機能";
"docs" = "ドキュメント";
"app_name" = "Clearcam";
diff --git a/ios/clearcam/ko.lproj/Localizable.strings b/ios/clearcam/ko.lproj/Localizable.strings
index 1fcddba..0881d25 100644
--- a/ios/clearcam/ko.lproj/Localizable.strings
+++ b/ios/clearcam/ko.lproj/Localizable.strings
@@ -3,7 +3,6 @@
"live" = "라이브";
"default_device_name" = "내 장치";
"waiting_for_ip" = "Wi-Fi 연결 대기 중...";
-"streaming_over_wifi" = "로컬 Wi-Fi로 스트리밍 중: %@";
"permission_denied" = "권한 거부됨";
"notification_permission_denied" = "알림 권한이 거부되었습니다. 설정에서 활성화할 수 있습니다.";
"ok" = "확인";
@@ -90,6 +89,8 @@
"delete" = "삭제";
"cancel" = "취소";
"online" = "온라인";
+"offline" = "오프라인";
+
"experimental_features" = "실험적 기능";
"docs" = "문서";
"app_name" = "Clearcam";
diff --git a/ios/clearcam/pt-BR.lproj/Localizable.strings b/ios/clearcam/pt-BR.lproj/Localizable.strings
index ca41dfd..7d6150b 100644
--- a/ios/clearcam/pt-BR.lproj/Localizable.strings
+++ b/ios/clearcam/pt-BR.lproj/Localizable.strings
@@ -3,7 +3,7 @@
"live" = "Ao Vivo";
"default_device_name" = "Meu Dispositivo";
"waiting_for_ip" = "Aguardando Wi-Fi...";
-"streaming_over_wifi" = "Transmitindo via Wi-Fi local em: %@";
+
"permission_denied" = "Permissão Negada";
"notification_permission_denied" = "Permissão de notificações negada. Ative em Configurações.";
"ok" = "OK";
@@ -99,6 +99,7 @@
"delete" = "Excluir";
"cancel" = "Cancelar";
"online" = "Online";
+"offline" = "Offline";
"experimental_features" = "Recursos Experimentais";
"docs" = "Documentação";
diff --git a/ios/clearcam/zh-Hans.lproj/Localizable.strings b/ios/clearcam/zh-Hans.lproj/Localizable.strings
index ecb461c..5678ee9 100644
--- a/ios/clearcam/zh-Hans.lproj/Localizable.strings
+++ b/ios/clearcam/zh-Hans.lproj/Localizable.strings
@@ -3,7 +3,6 @@
"live" = "直播";
"default_device_name" = "我的设备";
"waiting_for_ip" = "等待Wi-Fi连接...";
-"streaming_over_wifi" = "正在通过本地Wi-Fi串流,地址: %@";
"permission_denied" = "权限被拒绝";
"notification_permission_denied" = "通知权限被拒绝。您可以在设置中启用它。";
"ok" = "确定";
@@ -90,6 +89,7 @@
"delete" = "删除";
"cancel" = "取消";
"online" = "在线";
+"offline" = "离线";
"experimental_features" = "实验性功能";
"docs" = "文档";
"app_name" = "Clearcam";