-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🍎 iOS Permissions Changes to Comply with iOS Guidelines #237
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6946f45
make notifications permission optional
JGreenlee 987a432
implement "2 step" approach for location perms on iOS 13.4+
JGreenlee b92dd48
open app settings on notif perms prompt if initial prompt already shown
JGreenlee 5d5f1fd
update location perms warning strings
JGreenlee 84f5003
make iOS permissions descriptions not specific to OpenPATH
JGreenlee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -153,6 +153,16 @@ - (void) didChangeAuthorizationStatus:(CLAuthorizationStatus)status | |
CDVPluginResult* result = [CDVPluginResult | ||
resultWithStatus:CDVCommandStatus_OK]; | ||
[commandDelegate sendPluginResult:result callbackId:callbackId]; | ||
} else if (status == kCLAuthorizationStatusAuthorizedWhenInUse) { | ||
if (IsAtLeastiOSVersion(@"13.4")) { | ||
NSLog(@"iOS >=13.4 detected and 'whenInUse' authorized, need second step to request 'always'"); | ||
[[TripDiaryStateMachine delegate] registerForegroundDelegate:self]; | ||
[[TripDiaryStateMachine instance].locMgr requestAlwaysAuthorization]; | ||
if ([[UIApplication sharedApplication] applicationState] != UIApplicationStateInactive) { | ||
NSLog(@"App is active, i.e. request did not launch (happens if the user chose 'Allow Once' in step 1). Launching app settings to manually enable 'Always'"); | ||
[self openAppSettings]; | ||
} | ||
} | ||
} else { | ||
[LocalNotificationManager addNotification:[NSString stringWithFormat:@"status %d != always %d, returning error", status, kCLAuthorizationStatusAuthorizedAlways]]; | ||
NSString* msg = NSLocalizedStringFromTable(@"location_permission_off_app_open", @"DCLocalizable", nil); | ||
|
@@ -249,10 +259,17 @@ -(void) didRecieveFitnessPermission:(BOOL)isPermitted | |
- (void)checkAndPromptNotificationPermission { | ||
NSString* callbackId = [command callbackId]; | ||
@try { | ||
if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]) { | ||
UIUserNotificationSettings* requestedSettings = [TripDiarySensorControlChecks REQUESTED_NOTIFICATION_TYPES]; | ||
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasPromptedForUserNotification"]) { | ||
NSLog(@"Already prompted request for user notification. Launching app settings."); | ||
[AppDelegate registerForegroundDelegate:self]; | ||
[[UIApplication sharedApplication] registerUserNotificationSettings:requestedSettings]; | ||
[self openAppSettings]; | ||
} else { | ||
if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]) { | ||
NSLog(@"Requesting user notification settings"); | ||
UIUserNotificationSettings* requestedSettings = [TripDiarySensorControlChecks REQUESTED_NOTIFICATION_TYPES]; | ||
[AppDelegate registerForegroundDelegate:self]; | ||
[[UIApplication sharedApplication] registerUserNotificationSettings:requestedSettings]; | ||
} | ||
} | ||
} | ||
@catch (NSException *exception) { | ||
|
@@ -265,15 +282,15 @@ - (void)checkAndPromptNotificationPermission { | |
} | ||
|
||
- (void) didRegisterUserNotificationSettings:(UIUserNotificationSettings*)newSettings { | ||
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasPromptedForUserNotification"]; | ||
NSString* callbackId = [command callbackId]; | ||
UIUserNotificationSettings* requestedSettings = [TripDiarySensorControlChecks REQUESTED_NOTIFICATION_TYPES]; | ||
if (requestedSettings.types == newSettings.types) { | ||
CDVPluginResult* result = [CDVPluginResult | ||
resultWithStatus:CDVCommandStatus_OK]; | ||
[commandDelegate sendPluginResult:result callbackId:callbackId]; | ||
} else { | ||
NSString* msg = NSLocalizedStringFromTable(@"notifications_blocked_app_open", @"DCLocalizable", nil); | ||
[self openAppSettings]; | ||
NSString* msg = NSLocalizedStringFromTable(@"notifications_blocked", @"DCLocalizable", nil); | ||
CDVPluginResult* result = [CDVPluginResult | ||
resultWithStatus:CDVCommandStatus_ERROR | ||
messageAsString:msg]; | ||
|
@@ -282,25 +299,39 @@ - (void) didRegisterUserNotificationSettings:(UIUserNotificationSettings*)newSet | |
} | ||
|
||
-(void)promptForPermission:(CLLocationManager*)locMgr { | ||
if (IsAtLeastiOSVersion(@"13.0")) { | ||
NSLog(@"iOS 13+ detected, launching UI settings to easily enable always"); | ||
if (IsAtLeastiOSVersion(@"13.4")) { | ||
NSLog(@"iOS >=13.4 detected, using two-step approach of 'when in use' first and then 'always'"); | ||
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) { | ||
NSLog(@"Current location authorization = %d, when in use = %d, requesting when in use", | ||
[CLLocationManager authorizationStatus], kCLAuthorizationStatusAuthorizedWhenInUse); | ||
[[TripDiaryStateMachine delegate] registerForegroundDelegate:self]; | ||
[locMgr requestWhenInUseAuthorization]; | ||
} else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse) { | ||
NSLog(@"Current location authorization = %d, always = %d, requesting always", | ||
[CLLocationManager authorizationStatus], kCLAuthorizationStatusAuthorizedAlways); | ||
[[TripDiaryStateMachine delegate] registerForegroundDelegate:self]; | ||
[locMgr requestAlwaysAuthorization]; | ||
if ([[UIApplication sharedApplication] applicationState] != UIApplicationStateInactive) { | ||
NSLog(@"App is active, i.e. request did not launch (happens if the user chose 'Allow Once' in step 1). Launching app settings to manually enable 'Always'"); | ||
[self openAppSettings]; | ||
} | ||
} else { | ||
[[TripDiaryStateMachine delegate] registerForegroundDelegate:self]; | ||
[self openAppSettings]; | ||
} | ||
} else if (IsAtLeastiOSVersion(@"13.0")) { | ||
NSLog(@"iOS >=13,<13.4 detected, launching UI settings to manually enable 'always'"); | ||
// we want to leave the registration in the prompt for permission, since we don't want to register callbacks when we open the app settings for other reasons | ||
[[TripDiaryStateMachine delegate] registerForegroundDelegate:self]; | ||
[[TripDiaryStateMachine instance].locMgr startUpdatingLocation]; | ||
[self openAppSettings]; | ||
} | ||
else { | ||
} else { | ||
NSLog(@"iOS <13 detected, simply requesting 'always'"); | ||
Comment on lines
+328
to
+329
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we do not support iOS <13 anymore, so maybe this should be removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, we can remove that in a cleanup change |
||
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) { | ||
if ([CLLocationManager instancesRespondToSelector:@selector(requestAlwaysAuthorization)]) { | ||
NSLog(@"Current location authorization = %d, always = %d, requesting always", | ||
[CLLocationManager authorizationStatus], kCLAuthorizationStatusAuthorizedAlways); | ||
[[TripDiaryStateMachine delegate] registerForegroundDelegate:self]; | ||
[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"]; | ||
} | ||
NSLog(@"Current location authorization = %d, always = %d, requesting always", | ||
[CLLocationManager authorizationStatus], kCLAuthorizationStatusAuthorizedAlways); | ||
[[TripDiaryStateMachine delegate] registerForegroundDelegate:self]; | ||
[locMgr requestAlwaysAuthorization]; | ||
} else { | ||
// we want to leave the registration in the prompt for permission, since we don't want to register callbacks when we open the app settings for other reasons | ||
[[TripDiaryStateMachine delegate] registerForegroundDelegate:self]; | ||
|
@@ -347,11 +378,12 @@ - (void)locationManager:(CLLocationManager *)manager | |
if (foregroundDelegateList.count > 0) { | ||
[LocalNotificationManager addNotification:[NSString stringWithFormat:@"%lu foreground delegates found, calling didChangeAuthorizationStatus to return the new value %d", (unsigned long)foregroundDelegateList.count, status]]; | ||
|
||
int originalDelegateCount = (int)foregroundDelegateList.count; | ||
for (id currDelegate in foregroundDelegateList) { | ||
[currDelegate didChangeAuthorizationStatus:(CLAuthorizationStatus)status]; | ||
} | ||
[LocalNotificationManager addNotification:[NSString stringWithFormat:@"Notified all foreground delegates, removing all of them"]]; | ||
[foregroundDelegateList removeAllObjects]; | ||
[LocalNotificationManager addNotification:[NSString stringWithFormat:@"Notified all foreground delegates, removing %d delegates", originalDelegateCount]]; | ||
[foregroundDelegateList removeObjectsInRange:NSMakeRange(0, originalDelegateCount)]; | ||
} else { | ||
[LocalNotificationManager addNotification:[NSString stringWithFormat:@"No foreground delegate found, calling SensorControlBackgroundChecker from didChangeAuthorizationStatus to verify location service status and permission"]]; | ||
[SensorControlBackgroundChecker checkAppState]; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had left this vague because it felt like iOS kept adding new permissions and I didn't want to keep changing the plugin. But they haven't changed it for a while, and there are others who now have confidence in changing the native code, so this is fine.