Is it possible to check permission status while app is closed on iOS? My use case is I want to send out a notification at periodic intervals if the app does not have the “Always” location turned on.
Follow this Using Background Tasks to Update Your App.
You can do something when app is wakened by system to run in the background.
But if the user explicitly denies the AlwaysAuthorization permission, you should not ask the user periodically. It is very bad UX.
AppleStore reviewers may reject your app also.
I think you should find a suitable way to ask the user or only show a warning popup when the user opens app and use the function that requires AlwaysAuthorization. Or ask the user to grant this permission on the first app runs.
Changes in authorization state are typically detected using the locationManagerDidChangeAuthorization event in CLLocationManagerDelegate. However, when the app is closed, the user's status cannot be detected. You can use this method to detect the change of authorization status when the user is using the app.
For more details, you can refer to the following docs:
locationManagerDidChangeAuthorization
Related
My understanding since iOS 13 is that background location permissions can only be granted by the user after they have already granted foreground location permissions, and the app is in the background, when a location event which would have triggered the app's background location occurs. At that point they get a dialog something like:
Allow “App” to also access your location even when you are not using the app?
Every app I've used has the same behaviour, except one app, which is able to present that dialog immediately after asking for the foreground location permission dialog:
How does this app immediately and repeatedly trigger the background location dialog like this?
If your app has asked for and received "when in use" authorisation it can then ask for "always" authorisation to trigger a second permission dialog. This behaviour requires iOS 13.4 or later.
You should consider the user experience. I suggest that your app explains why it needs always authorisation before asking for it, otherwise the user may be peppered with permission requests
In my application I'm using Geofencing to track whether customer is currently present in the specified location while delivering an order.Is it possible to update his status to a server when he enters or exits geofence even when the app is in background?
It depends on what kind of location authorization you have. If you have 'always' authorization, you would be able to do it. If you have 'in-use' authorization, you would have a very small amount of time (~10s) to make the request before iOS suspends your app.
My application requires periodic location updates (every 10 minutes). In foreground and background (app not terminated) the application is working correctly. But the problem starts to occur when the app is terminated by the user.
I tried using this tutorial http://mobileoop.com/getting-location-updates-for-ios-7-and-8-when-the-app-is-killedterminatedsuspended .
It works only when user's location is changing because of startMonitoringSignificantLocationChanges. But I need locations in terminated state even if user is not changing its location.
Also, I have tried most of the stackoverflow questions but most of them gets satisfied with startMonitoringSignificantLocationChanges. But in my case it won't be enough to fulfil the application needs.
If a user terminates the app the system no longer grants it the same privileges. Background fetch operations and background location will not get executed until the user decides to start up your app again. The system recognizes this a user choice to not have this app running in any way again.
This isn't like the world of Android where an app can do as it pleases. Apple prefers user choice over what an app developer wants. This is of course good and bad as a developer. You need to provide the user with useful information about what your app is doing in the background so that they will allow it to run without terminating it. If they do terminate it, there is nothing that you can do.
My application requires periodic location updates (every 10 minutes). In foreground and background (app not terminated) the application is working correctly. But the problem starts to occur when the app is terminated by the user.
I tried using this tutorial http://mobileoop.com/getting-location-updates-for-ios-7-and-8-when-the-app-is-killedterminatedsuspended .
It works only when user's location is changing because of startMonitoringSignificantLocationChanges. But I need locations in terminated state even if user is not changing its location.
Also, I have tried most of the stackoverflow questions but most of them gets satisfied with startMonitoringSignificantLocationChanges. But in my case it won't be enough to fulfil the application needs.
If a user terminates the app the system no longer grants it the same privileges. Background fetch operations and background location will not get executed until the user decides to start up your app again. The system recognizes this a user choice to not have this app running in any way again.
This isn't like the world of Android where an app can do as it pleases. Apple prefers user choice over what an app developer wants. This is of course good and bad as a developer. You need to provide the user with useful information about what your app is doing in the background so that they will allow it to run without terminating it. If they do terminate it, there is nothing that you can do.
In ios, if I authorize or reject Location Services when prompted, there is a delegate method that gets called immediately:
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status;
I'm wondering if a similar method exists for accepting or rejecting Push Notifications. I'm aware of how to prompt, as well as how to test for status, but not how to do something immediately after a user accepts or rejects the notification.
I would like to prompt the user for Push Notification, and based on their response do a certain action, such as redirect the ViewController one way or another.
I've done a great deal of research on this and - unfortunately - the status of that accept/decline option appears to be entirely opaque.
You can determine that the user doesn't have push notifications enabled (using UIApplication's isRegisteredForRemoteNotifications), but not why it isn't enabled (ie. determine whether it's a "never prompted" or "prompted and then declined or later disabled" state).
I strongly suspect that this was a conscious design decision by Apple to make it more difficult for developers to hound users who've opted out. There are legitimate reasons to have this information, though, so I hope in the future they reconsider.
I hope this helps.
You can not do that but you can check that every time the app gets into foreground. This would solve your case when you can take action at the moment the user opens the app.
If you want to do that on background (in case you want to report your server that user has been disabled notification for example) you can always run some background task (like "Background fetch") to check the status.