-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #191 from shankari/improve_ios_onboarding
Improve ios onboarding
- Loading branch information
Showing
9 changed files
with
157 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
"dont-force-kill-please" = "Please don't force-kill. It actually increases battery drain because we don't get silent push notifications and can't stop tracking properly. Click to relaunch."; | ||
"dont-force-kill-please" = "Please don't quit the app. Keep it running in the background. Click to relaunch."; | ||
"new-data-collections-terms" = "New data collection terms - collection paused until consent"; | ||
"error-reading-activities" = "Error while reading activities"; | ||
"travel-mode-unavailable" = "Travel mode detection may be unavailable."; | ||
"activity-detection-unsupported" = "Activity detection unsupported"; | ||
"activity-permission-problem" = "The app does not have permission to read your motion activities - automatic mode detection will not work. Please fix in Settings -> Privacy -> Motion & Fitness"; | ||
"activity-permission-problem" = "No 'Motion & Fitness' permission - automatic mode detection will not work. Turn it on (Settings -> app)"; | ||
"activity-turned-off-problem" = "Motion & Fitness Service disabled - automatic mode detection will not work. Turn it on (Settings -> Privacy)"; | ||
"travel-mode-unknown" = "Travel mode detection unavailable - all trips will be UNKNOWN."; | ||
"bad-loc-tracking-problem" = "Background location accuracy is consistently poor - trip tracking may not work. Try to resolve the problem by turning location services, WiFi and cellular data off and on. If this message persists, please 'Email Log' for additional investigation"; | ||
"location-turned-off-problem" = "Location Services are turned off - trip tracking will not work. Try to resolve the problem by turning on location services (Settings -> Privacy)"; | ||
"location-permission-problem" = "The app does not have the 'always' permission - background trip tracking will not work. Please fix in Settings -> Privacy -> Location Services"; | ||
"bad-loc-tracking-problem" = "Background location accuracy is consistently poor - trip tracking may not work. Report problem."; | ||
"location-turned-off-problem" = "Location Services are turned off - trip tracking will not work. Turn it on (Settings -> Privacy)"; | ||
"fix-service-action-button" = "Launch Settings"; | ||
"permission-problem-title" = "Incorrect permission"; | ||
"location-permission-problem" = "The app does not have the 'always' permission - background trip tracking will not work."; | ||
"fix-permission-action-button" = "Fix permission"; | ||
"precise-location-problem" = "The app does not have permission to read 'precise' location - background trip tracking will not work."; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,143 @@ | ||
#import "TripDiarySettingsCheck.h" | ||
#import "LocalNotificationManager.h" | ||
#import "BEMAppDelegate.h" | ||
#import "BEMActivitySync.h" | ||
|
||
#import <CoreMotion/CoreMotion.h> | ||
|
||
@implementation TripDiarySettingsCheck | ||
|
||
+(void)checkSettingsAndPermission { | ||
[TripDiarySettingsCheck checkLocationSettingsAndPermission:TRUE]; | ||
[TripDiarySettingsCheck checkMotionSettingsAndPermission:TRUE]; | ||
} | ||
|
||
+(void)checkLocationSettingsAndPermission:(BOOL)inBackground { | ||
if (![CLLocationManager locationServicesEnabled]) { | ||
// first, check to see if location services are enabled | ||
[LocalNotificationManager addNotification:[NSString stringWithFormat:@"in checkLocationSettingsAndPermissions, locationService is not enabled"]]; | ||
|
||
NSString* errorDescription = NSLocalizedStringFromTable(@"location-turned-off-problem", @"DCLocalizable", nil); | ||
if (inBackground) { | ||
[LocalNotificationManager showNotificationAfterSecs:errorDescription withUserInfo:NULL secsLater:60]; | ||
} | ||
} else { | ||
// next, check to see if it is "always" | ||
if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorizedAlways) { | ||
[LocalNotificationManager addNotification:[NSString stringWithFormat:@"in checkLocationSettingsAndPermissions, locationService is enabled, but the permission is %d", [CLLocationManager authorizationStatus]]]; | ||
|
||
NSString* errorDescription = NSLocalizedStringFromTable(@"location-permission-problem", @"DCLocalizable", nil); | ||
if (inBackground) { | ||
[LocalNotificationManager showNotificationAfterSecs:errorDescription withUserInfo:NULL secsLater:60]; | ||
} | ||
[TripDiarySettingsCheck showLaunchSettingsAlert:@"permission-problem-title" withMessage:@"location-permission-problem" button:@"fix-permission-action-button"]; | ||
} else { | ||
// finally, check to see if it is "precise" | ||
// we currently check these in a cascade, since generating multiple alerts results in | ||
// "Attempt to present <UIAlertController: 0x7fd6c1018400> on <MainViewController: 0x7fd6e7c0a2a0> (from <MainViewController: 0x7fd6e7c0a2a0>) which is already presenting <UIAlertController: 0x7fd6e000ac00>." | ||
CLLocationManager* currLocMgr = [TripDiaryStateMachine instance].locMgr; | ||
if (@available(iOS 14.0, *)) { | ||
CLAccuracyAuthorization preciseOrNot = [currLocMgr accuracyAuthorization]; | ||
[LocalNotificationManager addNotification:[NSString stringWithFormat:@"in checkLocationSettingsAndPermissions, locationService is enabled, permission is 'always', accuracy status is %ld", preciseOrNot]]; | ||
if (preciseOrNot != CLAccuracyAuthorizationFullAccuracy) { | ||
[TripDiarySettingsCheck showLaunchSettingsAlert:@"permission-problem-title" withMessage:@"precise-location-problem" button:@"fix-permission-action-button"]; | ||
} | ||
} else { | ||
[LocalNotificationManager addNotification:[NSString stringWithFormat:@"No precise location check needed for iOS < 14"]]; | ||
} | ||
} | ||
} | ||
} | ||
|
||
+(void)promptForPermission:(CLLocationManager*)locMgr { | ||
if (IsAtLeastiOSVersion(@"13.0")) { | ||
NSLog(@"iOS 13+ detected, launching UI settings to easily enable always"); | ||
[TripDiarySettingsCheck openAppSettings]; | ||
} | ||
else if ([CLLocationManager instancesRespondToSelector:@selector(requestAlwaysAuthorization)]) { | ||
NSLog(@"Current location authorization = %d, always = %d, requesting always", | ||
[CLLocationManager authorizationStatus], kCLAuthorizationStatusAuthorizedAlways); | ||
[locMgr requestAlwaysAuthorization]; | ||
} else { | ||
// TODO: should we remove this? Not sure when it will ever be called, given that | ||
// requestAlwaysAuthorization is available in iOS8+ | ||
[LocalNotificationManager addNotification:@"Don't need to request authorization, system will automatically prompt for it"]; | ||
} | ||
} | ||
|
||
+(void)checkMotionSettingsAndPermission:(BOOL)inBackground { | ||
if ([CMMotionActivityManager isActivityAvailable] == YES) { | ||
[LocalNotificationManager addNotification:@"Motion activity available, checking auth status"]; | ||
CMAuthorizationStatus currAuthStatus = [CMMotionActivityManager authorizationStatus]; | ||
[LocalNotificationManager addNotification:[NSString stringWithFormat:@"Auth status = %ld", currAuthStatus]]; | ||
|
||
if (currAuthStatus == CMAuthorizationStatusRestricted) { | ||
[LocalNotificationManager addNotification:[NSString stringWithFormat:@"Activity detection not enabled, prompting user to change Settings"]]; | ||
if (inBackground) { | ||
NSString* errorDescription = NSLocalizedStringFromTable(@"activity-turned-off-problem", @"DCLocalizable", nil); | ||
[LocalNotificationManager showNotificationAfterSecs:errorDescription withUserInfo:NULL secsLater:60]; | ||
} | ||
[TripDiarySettingsCheck showLaunchSettingsAlert:@"activity-detection-unsupported" withMessage:@"activity-turned-off-problem" button:@"fix-service-action-button"]; | ||
} | ||
if (currAuthStatus == CMAuthorizationStatusNotDetermined) { | ||
[LocalNotificationManager addNotification:[NSString stringWithFormat:@"Activity status not determined, initializing to get regular prompt"]]; | ||
[BEMActivitySync initWithConsent]; | ||
} | ||
if ([CMMotionActivityManager authorizationStatus] == CMAuthorizationStatusDenied) { | ||
[LocalNotificationManager addNotification:[NSString stringWithFormat:@"Activity status denied, opening app settings to enable"]]; | ||
NSString* errorDescription = NSLocalizedStringFromTable(@"activity-permission-problem", @"DCLocalizable", nil); | ||
if (inBackground) { | ||
[LocalNotificationManager showNotificationAfterSecs:errorDescription withUserInfo:NULL secsLater:60]; | ||
} | ||
[TripDiarySettingsCheck showLaunchSettingsAlert:@"permission-problem-title" withMessage:@"activity-permission-problem" button:@"fix-permission-action-button"]; | ||
} | ||
} else { | ||
[LocalNotificationManager addNotification:[NSString stringWithFormat:@"Activity detection unsupported, all trips will be UNKNOWN"]]; | ||
NSString* title = NSLocalizedStringFromTable(@"activity-detection-unsupported", @"DCLocalizable", nil); | ||
NSString* message = NSLocalizedStringFromTable(@"travel-mode-unknown", @"DCLocalizable", nil); | ||
|
||
UIAlertController* alert = [UIAlertController alertControllerWithTitle:title | ||
message:message | ||
preferredStyle:UIAlertControllerStyleAlert]; | ||
|
||
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault | ||
handler:^(UIAlertAction * action) { | ||
}]; | ||
[alert addAction:defaultAction]; | ||
[TripDiarySettingsCheck showSettingsAlert:alert]; | ||
} | ||
} | ||
|
||
+(void)showLaunchSettingsAlert:(NSString*)titleTag withMessage:(NSString*)messageTag button:(NSString*)buttonTag { | ||
NSString* title = NSLocalizedStringFromTable(titleTag, @"DCLocalizable", nil); | ||
NSString* message = NSLocalizedStringFromTable(messageTag, @"DCLocalizable", nil); | ||
NSString* errorAction = NSLocalizedStringFromTable(buttonTag, @"DCLocalizable", nil); | ||
|
||
UIAlertController* alert = [UIAlertController alertControllerWithTitle:title | ||
message:message | ||
preferredStyle:UIAlertControllerStyleAlert]; | ||
|
||
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:errorAction style:UIAlertActionStyleDefault | ||
handler:^(UIAlertAction * action) { | ||
[TripDiarySettingsCheck openAppSettings]; | ||
}]; | ||
[alert addAction:defaultAction]; | ||
[TripDiarySettingsCheck showSettingsAlert:alert]; | ||
} | ||
|
||
+(void) openAppSettings { | ||
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:^(BOOL success) { | ||
if (success) { | ||
NSLog(@"Opened url"); | ||
} else { | ||
NSLog(@"Failed open"); | ||
}}]; | ||
} | ||
|
||
+(void) showSettingsAlert:(UIAlertController*)alert { | ||
CDVAppDelegate *ad = [[UIApplication sharedApplication] delegate]; | ||
CDVViewController *vc = ad.viewController; | ||
[vc presentViewController:alert animated:YES completion:nil]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters