找出用户在iOS显示的UIAlertView上选择的按钮的方式,请求允许该应用接收推送通知的权限

时间:2014-02-10 09:55:52

标签: ios iphone apple-push-notifications uialertview

有没有办法与iOS的警报显示进行交互。例如:如果我的应用已经注册了自己的APNS,首次启动时,iOS会显示UIAlertView(我假设,它是一个),给用户两个choice.Is有办法找出用户选择的按钮? 我在应用启动期间显示了两个警报,一个用于APNS,另一个用于位置服务。是否有办法识别哪个警报用于什么?

5 个答案:

答案 0 :(得分:1)

没有。无法在操作系统创建的AlertViews上获得回调。与CoolMonster在评论中指出的一样,您可以找出用户为该特定AlertView选择的内容,并根据该内容执行某些操作。

答案 1 :(得分:1)

如果您无法直接访问这些提醒,我建议您从另一个角度来看待这个问题。

对于CoreLocation,您可以查看其[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.

对于APNS,有[[UIApplication sharedApplication] enabledRemoteNotificationTypes]

来源: https://developer.apple.com/library/ios/documentation/uikit/reference/UIApplication_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UIRemoteNotificationType

https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html#//apple_ref/doc/c_ref/CLAuthorizationStatus

答案 2 :(得分:0)

我不知道推送通知,但这是一种(丑陋的)方式,在要求获取用户位置的权限时检测用户的选择:

// 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");
}

答案 3 :(得分:0)

您可以获得以下通知类型:

UIRemoteNotificationType notificationTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

并且可能会创建一些黑客方法来让用户与通知问题进行交互

答案 4 :(得分:0)

虽然可能没有明确的方法来了解用户点击的按钮,但您可以通过实施这些UIApplication委托方法来确定用户是否授权使用推送通知:

application:didRegisterForRemoteNotificationsWithDeviceToken:(用户接受)

application:didFailToRegisterForRemoteNotificationsWithError:(用户拒绝或无法接受)