Add object detection, tracking, mobile notifications, and search to any security camera.
get new token before failing to send?
roryclear8ba8409ec167
diff --git a/clearcam/SceneState.h b/clearcam/SceneState.hindex 70ec4bd..e54e1d0 100644--- a/clearcam/SceneState.h+++ b/clearcam/SceneState.h@@ -11,5 +11,6 @@@property (strong, nonatomic) NSManagedObjectContext *backgroundContext;@property (strong, nonatomic) NSDate *last_email_time;- (void)processOutput:(NSArray *)array withImage:(CIImage *)image;+- (void)sendEmail:(NSString *)filePath; //todo, remove@enddiff --git a/clearcam/SceneState.m b/clearcam/SceneState.mindex dfef98d..e79d8db 100644--- a/clearcam/SceneState.m+++ b/clearcam/SceneState.m@@ -106,44 +106,15 @@if(![[NSUserDefaults standardUserDefaults] boolForKey:@"isSubscribed"] || ![[NSDate date] compare:[[NSUserDefaults standardUserDefaults] objectForKey:@"expiry"]] || [[NSDate date] compare:[[NSUserDefaults standardUserDefaults] objectForKey:@"expiry"]] == NSOrderedDescending){NSLog(@"verifying subscription");[[StoreManager sharedInstance] verifySubscriptionWithCompletion:^(BOOL isActive, NSDate *expiryDate) {- //do nothing, todo, need to send the notif here?+ [self sendEmail:filePath];}];+ } else {+ [self sendEmail:filePath];}+ //todo//if ([[NSUserDefaults standardUserDefaults] boolForKey:@"send_email_alerts_enabled"] &&// ([[NSUserDefaults standardUserDefaults] boolForKey:@"isSubscribed"] ||// [[NSUserDefaults standardUserDefaults] boolForKey:@"use_own_email_server_enabled"])) {- if ([[NSUserDefaults standardUserDefaults] boolForKey:@"send_email_alerts_enabled"] || !([[NSUserDefaults standardUserDefaults] boolForKey:@"isSubscribed"] || [[NSUserDefaults standardUserDefaults] boolForKey:@"use_own_email_server_enabled"])){ //todo add back other stuff- //if ([[NSUserDefaults standardUserDefaults] boolForKey:@"send_email_alerts_enabled"]){ //todo add back other stuff- // Get the current hour- NSDate *now = [NSDate date];- NSDateComponents *components = [[NSCalendar currentCalendar] components:(NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitWeekday) fromDate:now];- NSInteger currentTime = components.hour * 60 + components.minute;- NSString *currentDay = @[@"Sun", @"Mon", @"Tue", @"Wed", @"Thu", @"Fri", @"Sat"][components.weekday - 1];-- for (NSDictionary *schedule in [[NSUserDefaults standardUserDefaults] arrayForKey:@"email_schedules"] ?: @[]) {- if (![schedule[@"enabled"] boolValue]) continue;- if (![schedule[@"days"] containsObject:currentDay]) continue;-- NSInteger startTime = [schedule[@"startHour"] integerValue] * 60 + [schedule[@"startMinute"] integerValue];- NSInteger endTime = [schedule[@"endHour"] integerValue] * 60 + [schedule[@"endMinute"] integerValue];-- if (currentTime >= startTime && currentTime <= endTime) {- [[Email sharedInstance] sendEmailWithImageAtPath:filePath];- self.last_email_time = now;- if([FileServer sharedInstance].segment_length > 3) [FileServer sharedInstance].segment_length = 3;- NSTimeInterval start = [[NSDate dateWithTimeIntervalSinceNow:-7.5] timeIntervalSince1970];- NSTimeInterval end = [[NSDate dateWithTimeIntervalSinceNow:7.5] timeIntervalSince1970];- id context = [FileServer sharedInstance].context;- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{- NSString *filePath = [[FileServer sharedInstance] processVideoDownloadWithLowRes:YES startTime:start endTime:end context:context];- [[Email sharedInstance] sendEmailWithImageAtPath:filePath];- });- NSLog(@"Email sent: Within scheduled time");- break;- }- }- NSLog(@"Email suppressed: Outside scheduled time or no matching schedule");- }} else {NSLog(@"NOT sending an email");}@@ -172,4 +143,37 @@}}+- (void)sendEmail:(NSString *)filePath {+ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"send_email_alerts_enabled"] || !([[NSUserDefaults standardUserDefaults] boolForKey:@"isSubscribed"] || [[NSUserDefaults standardUserDefaults] boolForKey:@"use_own_email_server_enabled"])){ //todo add back other stuff+ NSDate *now = [NSDate date];+ NSDateComponents *components = [[NSCalendar currentCalendar] components:(NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitWeekday) fromDate:now];+ NSInteger currentTime = components.hour * 60 + components.minute;+ NSString *currentDay = @[@"Sun", @"Mon", @"Tue", @"Wed", @"Thu", @"Fri", @"Sat"][components.weekday - 1];++ for (NSDictionary *schedule in [[NSUserDefaults standardUserDefaults] arrayForKey:@"email_schedules"] ?: @[]) {+ if (![schedule[@"enabled"] boolValue]) continue;+ if (![schedule[@"days"] containsObject:currentDay]) continue;++ NSInteger startTime = [schedule[@"startHour"] integerValue] * 60 + [schedule[@"startMinute"] integerValue];+ NSInteger endTime = [schedule[@"endHour"] integerValue] * 60 + [schedule[@"endMinute"] integerValue];++ if (currentTime >= startTime && currentTime <= endTime) {+ [[Email sharedInstance] sendEmailWithImageAtPath:filePath];+ self.last_email_time = now;+ if([FileServer sharedInstance].segment_length > 3) [FileServer sharedInstance].segment_length = 3;+ NSTimeInterval start = [[NSDate dateWithTimeIntervalSinceNow:-7.5] timeIntervalSince1970];+ NSTimeInterval end = [[NSDate dateWithTimeIntervalSinceNow:7.5] timeIntervalSince1970];+ id context = [FileServer sharedInstance].context;+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{+ NSString *filePath = [[FileServer sharedInstance] processVideoDownloadWithLowRes:YES startTime:start endTime:end context:context];+ [[Email sharedInstance] sendEmailWithImageAtPath:filePath];+ });+ NSLog(@"Email sent: Within scheduled time");+ break;+ }+ }+ NSLog(@"Email suppressed: Outside scheduled time or no matching schedule");+ }+}+@end