From 0d1e96d81affc365908388197ebf36df2c31eabc Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Wed, 4 Sep 2013 15:56:37 -0700 Subject: [PATCH] Adding reachability preference (wifi only vs wifi + cellular). --- clients/ios/Classes/NewsBlurAppDelegate.h | 1 + clients/ios/Classes/NewsBlurAppDelegate.m | 14 ++++++++++++++ clients/ios/Classes/offline/OfflineFetchImages.m | 9 +++++++++ .../ios/Classes/offline/OfflineFetchStories.m | 6 ++++-- clients/ios/Entitlements.entitlements | 2 +- clients/ios/NewsBlur-iPhone-Info.plist | 4 ++-- clients/ios/NewsBlur.xcodeproj/project.pbxproj | 16 ++++++++-------- 7 files changed, 39 insertions(+), 13 deletions(-) diff --git a/clients/ios/Classes/NewsBlurAppDelegate.h b/clients/ios/Classes/NewsBlurAppDelegate.h index fca7039ac..2075f9ce1 100644 --- a/clients/ios/Classes/NewsBlurAppDelegate.h +++ b/clients/ios/Classes/NewsBlurAppDelegate.h @@ -352,6 +352,7 @@ - (void)startOfflineQueue; - (void)startOfflineFetchStories; - (void)startOfflineFetchImages; +- (BOOL)isReachabileForOffline; - (void)queueReadStories:(NSDictionary *)feedsStories; - (void)flushQueuedReadStories:(BOOL)forceCheck withCallback:(void(^)())callback; - (void)syncQueuedReadStories:(FMDatabase *)db withStories:(NSDictionary *)hashes withCallback:(void(^)())callback; diff --git a/clients/ios/Classes/NewsBlurAppDelegate.m b/clients/ios/Classes/NewsBlurAppDelegate.m index 1632478fd..ba48e8c74 100644 --- a/clients/ios/Classes/NewsBlurAppDelegate.m +++ b/clients/ios/Classes/NewsBlurAppDelegate.m @@ -2313,6 +2313,20 @@ [offlineQueue addOperation:operationFetchImages]; } +- (BOOL)isReachabileForOffline { + Reachability *reachability = [Reachability reachabilityForInternetConnection]; + NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus]; + + NSString *connection = [[NSUserDefaults standardUserDefaults] + stringForKey:@"offline_download_connection"]; + + NSLog(@"Reachable via: %d / %d", remoteHostStatus == ReachableViaWWAN, remoteHostStatus == ReachableViaWiFi); + if ([connection isEqualToString:@"wifi"] && remoteHostStatus != ReachableViaWiFi) { + return NO; + } + + return YES; +} - (void)queueReadStories:(NSDictionary *)feedsStories { [self.database inTransaction:^(FMDatabase *db, BOOL *rollback) { diff --git a/clients/ios/Classes/offline/OfflineFetchImages.m b/clients/ios/Classes/offline/OfflineFetchImages.m index 6827193c0..637b4464d 100644 --- a/clients/ios/Classes/offline/OfflineFetchImages.m +++ b/clients/ios/Classes/offline/OfflineFetchImages.m @@ -52,6 +52,15 @@ }); return NO; } + + if (![appDelegate isReachabileForOffline]) { + dispatch_async(dispatch_get_main_queue(), ^{ + [appDelegate.feedsViewController showDoneNotifier]; + [appDelegate.feedsViewController hideNotifier]; + }); + return NO; + } + NSMutableArray *downloadRequests = [NSMutableArray array]; for (NSArray *urlArray in urls) { diff --git a/clients/ios/Classes/offline/OfflineFetchStories.m b/clients/ios/Classes/offline/OfflineFetchStories.m index e9d8d44fb..49665f04d 100644 --- a/clients/ios/Classes/offline/OfflineFetchStories.m +++ b/clients/ios/Classes/offline/OfflineFetchStories.m @@ -34,8 +34,10 @@ } - if (![[[NSUserDefaults standardUserDefaults] - objectForKey:@"offline_allowed"] boolValue]) { + BOOL offlineAllowed = [[[NSUserDefaults standardUserDefaults] + objectForKey:@"offline_allowed"] boolValue]; + if (!offlineAllowed || + ![appDelegate isReachabileForOffline]) { dispatch_async(dispatch_get_main_queue(), ^{ [appDelegate.feedsViewController showDoneNotifier]; [appDelegate.feedsViewController hideNotifier]; diff --git a/clients/ios/Entitlements.entitlements b/clients/ios/Entitlements.entitlements index fe238e5c4..c468210c7 100644 --- a/clients/ios/Entitlements.entitlements +++ b/clients/ios/Entitlements.entitlements @@ -5,7 +5,7 @@ application-identifier $(AppIdentifierPrefix)$(CFBundleIdentifier) get-task-allow - + keychain-access-groups $(AppIdentifierPrefix)$(CFBundleIdentifier) diff --git a/clients/ios/NewsBlur-iPhone-Info.plist b/clients/ios/NewsBlur-iPhone-Info.plist index 41b22b860..e7bda896f 100644 --- a/clients/ios/NewsBlur-iPhone-Info.plist +++ b/clients/ios/NewsBlur-iPhone-Info.plist @@ -49,7 +49,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 2.4.3 + 2.4.4 CFBundleSignature ???? CFBundleURLTypes @@ -78,7 +78,7 @@ CFBundleVersion - 2.4.3 + 2.4.4 FacebookAppID 230426707030569 LSRequiresIPhoneOS diff --git a/clients/ios/NewsBlur.xcodeproj/project.pbxproj b/clients/ios/NewsBlur.xcodeproj/project.pbxproj index b395e234e..151521c19 100755 --- a/clients/ios/NewsBlur.xcodeproj/project.pbxproj +++ b/clients/ios/NewsBlur.xcodeproj/project.pbxproj @@ -2658,8 +2658,8 @@ ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; CODE_SIGN_ENTITLEMENTS = Entitlements.entitlements; - CODE_SIGN_IDENTITY = "iPhone Distribution: NewsBlur, Inc."; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution: NewsBlur, Inc."; + CODE_SIGN_IDENTITY = "iPhone Developer: Samuel Clay (G9HFWP68T7)"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Samuel Clay (G9HFWP68T7)"; COPY_PHASE_STRIP = NO; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; @@ -2682,8 +2682,8 @@ "-all_load", ); PRODUCT_NAME = NewsBlur; - PROVISIONING_PROFILE = "EE8BC292-FFF2-41A0-AE29-C4B39D6A2C5A"; - "PROVISIONING_PROFILE[sdk=iphoneos*]" = "EE8BC292-FFF2-41A0-AE29-C4B39D6A2C5A"; + PROVISIONING_PROFILE = ""; + "PROVISIONING_PROFILE[sdk=iphoneos*]" = ""; TARGETED_DEVICE_FAMILY = "1,2"; VALID_ARCHS = armv7; "WARNING_CFLAGS[arch=*]" = "-Wall"; @@ -2697,8 +2697,8 @@ ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; CODE_SIGN_ENTITLEMENTS = Entitlements.entitlements; - CODE_SIGN_IDENTITY = "iPhone Distribution: NewsBlur, Inc."; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution: NewsBlur, Inc."; + CODE_SIGN_IDENTITY = "iPhone Developer: Samuel Clay (G9HFWP68T7)"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Samuel Clay (G9HFWP68T7)"; COPY_PHASE_STRIP = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = NewsBlur_Prefix.pch; @@ -2718,8 +2718,8 @@ "-all_load", ); PRODUCT_NAME = NewsBlur; - PROVISIONING_PROFILE = "EE8BC292-FFF2-41A0-AE29-C4B39D6A2C5A"; - "PROVISIONING_PROFILE[sdk=iphoneos*]" = "EE8BC292-FFF2-41A0-AE29-C4B39D6A2C5A"; + PROVISIONING_PROFILE = ""; + "PROVISIONING_PROFILE[sdk=iphoneos*]" = ""; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VALID_ARCHS = armv7;