Calling [CLLocationManager requestAlwaysAuthorization] doesnt show the alert after the user selected "Dont Allow" option for the first time. Is there anyway to force the app to show the alert again when needed?
Apple won't display your alert if the user has already pressed Don't Allow.
On the other hand, you can check the authorization status and show a pop telling the user to go to settings and changing it manually.
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
if (status == kCLAuthorizationStatusNotDetermined) {
// Show request
}
Regards
Related
if my app is requesting GPS location, there's a dialog shown to user asking permission.
and my app also check the authorization, if the user not allow use location service, I will also prompt a dialog to notify user to do the settings.
now the question is, when I first launch the app, the user haven't allow yet, but the check code also executed, so it will show a dialog beneath the system privacy dialog. now it has two scenarios:
user click Don't allow, the system dialog dismissed, and my dialog appear, say app don't have permission to locate, that's right.
but if user click Allow, my will also shown because it's right there, beneath the system's dialog.
I now can only put the two part code different place, but is there a better or more reasonable way to solve this? which is, if user clicked allow, I will know.
some thoughts:
1. if I can know there's a system's privacy dialog been presenting (not a better way, because I just want to know location privacy
2. how to know the location privacy dialog's presenter, so I will use it to check if it has presenting a dialog
3. how to know what action did user do after the privacy dialog is shown can user clicked to dismiss.
Implement didChangeAuthorizationStatus delegate method from location manager and check authorization there
func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
switch status {
case .NotDetermined:
// show alert here
break
case .AuthorizedWhenInUse:
break
case .AuthorizedAlways:
break
case .Restricted:
// show alert here
break
case .Denied:
// show alert here
break
default:
break
}
}
Can we handle the buttons of notification's permission alert? I have attached an image of this alert. This alerts comes when we install the app for the first time on a device. If the user clicks on "Don't Allow" then the notification feature will be disabled for this app.
So, if the user clicks "Don't Allow", then I want to display a confirmation alert and inform the user that they can enable it from settings again. For this purpose I need to handle notification Alert's button (see the attached image).
If anyone knows the answer to this, please reply.
Thank you.
If push notifications were disallowed by user the delegate method :
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err { }
should be called. This should be the place to show your alert view.
Give it a try!
Cheers
I am new to this and this is my first question.
Would any one let me know whether we can or cannot pop a System Alert on UISwitch's 'ON' state.
I Know we can have custom alert but i don't want that.It is related to GPS whereby when the user switches on the switch it should give you an System Alert asking to on your GPS.
No, it's automatically displayed when the app accesses Core Location. If the user rejects it, it's displayed a second time at the next launch, then it keeps quiet and is not shown anymore.
So there is no way you could force this dialog to show again. iOS will ask the user again on the next start-up of the app.
Edit : If you need to show an alert for GPS you van check whether GPS is enabled or not as if userlocation is nil or not. if it is not nil then set your switch enabled else set disbled.
MKUserLocation *userLocation = mapView.userLocation;
if (!userLocation.location)
{
// Show an alert here to turn on Location service
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Location Service Disabled"
message:#"To re-enable, please go to Settings and turn on Location Service for this app."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
So user can enable GPS in settings directly.
Hope it helps you.
I want to know and take some action if the user has pressed cancel button in the
"Turn On Location Services" prompt. I have tried creating a breakpoint on the
(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
delegate method but this breakpoint does not get hit.
I want to know if the location services is off and the user has hit cancel so that I may not get into the same workflow again and again.
Implement the CLLocationManagerDelegate's locationManager:didChangeAuthorizationStatus: method. When your app launches, the authorization status will be kCLAuthorizationStatusNotDetermined. When the user chooses Yes or No, this method will be called with a status of kCLAuthorizationStatusAuthorized or kCLAuthorizationStatusDenied.
I need the app gives an alert when it's running in foreground
I test it in my device , when it's in background , the alert shows ; But when app comes in foreground , no alert shows , does this happen by default ?
I've searched some questions , someone says that I can mimic an alert using "UIAlertView"...
Is there any other proper way to do this ?
When your app is foreground, you have to handle the notification. The system won't pop up an alert for you, you have to catch the notification in application:didReceiveRemoteNotification: and deal with it yourself.
If you want an alert, then in that method you should summon a UIAlertView.
I'll do like this:
if ([UIApplication sharedApplication].applicationState != UIApplicationStateBackground) {
// show an alert view
}
else {
// your local notification configuration
}
#Kjuly is right with the above, but you should also check for UIApplicationStateInactive. It may be easier just to check if
[UIApplication sharedApplication].applicationState != UIApplicationStateActive