Is there a way to interact with the alerts show by iOS.For eg: If my app has registered itself for APNS,on first launch, iOS shows an UIAlertView(I am assuming,it is one),giving the user two choices.Is there a way to find out which button the user selected? I have two alerts that are shown ,during my app launch,one for APNS and the other for Location Services.Is there a way to identify which alert is for what?
-
http://stackoverflow.com/questions/1535403/determine-on-iphone-if-user-has-enabled-push-notifications this may help u but not as u expect. – CoolMonster Feb 10 '14 at 10:07
-
Thank you @CoolMonster.I did see that.I am already doing that.I was trying to see if there was a way to handle the button click ,like we do for an UIAlertView,i create. – wannabe_klear Feb 10 '14 at 10:19
5 Answers
No. There is no way to get callbacks on the AlertViews created by the OS. Like CoolMonster indicated in his comment, you can find out what the user chose for that particular AlertView and do something based off that.

- 14,445
- 5
- 38
- 62
In case you can't access those alerts directly I suggest you to look at this problem from another point of view.
For CoreLocation for example you can look at its [CLLocationManager authorizationStatus]
.
kCLAuthorizationStatusNotDetermined = 0, // User wasn't proposed to use location services
kCLAuthorizationStatusRestricted, // Parental control or something like that
kCLAuthorizationStatusDenied, // User didn't allow this application to use services
kCLAuthorizationStatusAuthorized // User allowed to use his location.
As for APNS there are [[UIApplication sharedApplication] enabledRemoteNotificationTypes]

- 848
- 9
- 15
I don't know about push notifications but here's one (ugly) way of detecting the user's choice when asking for permissions to get user's location:
// After asking for permission, the alert is shown to the user. Since he can't do anything
// at this point but select one of the two options we simply wait...
while(([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined))
{
sleep(1);
}
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized)
{
NSLog(@"User allowed access to gps");
}
else
{
NSLog(@"User denied access to gps");
}

- 2,867
- 25
- 35
You can get notification types like this:
UIRemoteNotificationType notificationTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
And may create some hack ways to get user's interaction to Notifications question

- 4,787
- 3
- 20
- 19
-
Thank you @nerowolfe.I did try this method.Also i tried enumerating the subview of self.window in "applicationWillResignActive:",but i am not able to see UIAlertView as a subview. – wannabe_klear Feb 10 '14 at 10:45
-
I think you can't catch this UIAlertView specifically, so you can only find out later if user did not allow remote notifications for your app. – nerowolfe Feb 10 '14 at 10:46
-
Yes,i was thinking on the same lines,@nerowolfe.It appears to be impossible. – wannabe_klear Feb 10 '14 at 10:53
-
This particular post has a way to do what i want. http://stackoverflow.com/questions/18702565/find-uialertview-without-having-reference-to-it-ios-7/19275311#19275311 From what i see(__attribute__((visibility("hidden")))),It appears to be a private class,hence cannot be used in an app to be submitted to the app store http://developer.limneos.net/headers/4.0/UIKit.framework/Headers/_UIAlertManager.h – wannabe_klear Feb 10 '14 at 11:36
Though there may not be a clear-cut way to know what button the user clicked on, you can certainly find out if the user authorized or not the use of push notifications by implementing these UIApplication delegate methods:
application:didRegisterForRemoteNotificationsWithDeviceToken: (User accepted)
application:didFailToRegisterForRemoteNotificationsWithError: (User denied or is not able to accept)

- 2,573
- 19
- 21
-
Thank you for your suggestion.I ended up using "enabledRemoteNotificationTypes:". as suggested by Yuri Romanchenko. – wannabe_klear Feb 14 '14 at 09:55