iOS8 - 要求远程推送通知

时间:2014-10-02 08:10:56

标签: ios permissions ios8 push-notification

有关用户接受推送通知(以及徽章等通知)的iOS8更改的两个问题。

1)我正在使用目前在iOS7和iOS8上都运行良好的方法

if ([[[UIDevice currentDevice] systemVersion] floatValue]>= 8.0) {
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:
(UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert)
categories:nil];        
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
    [[UIApplication sharedApplication] registerForRemoteNotifications];        
} else {
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
     (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}

这完全起作用,因为推送和警报正在工作,我在didRegister委托方法中获得了令牌,但我从未被问过弹出窗口,因为它曾经是这种情况。即使我从手机中删除了应用程序? 为什么?操作系统是否会保留应用程序的内存隐私设置,即使它们已被删除?

2)我看到有人建议在以下代表中要求远程通知

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{        
    NSLog(@"registered for notifications settings %@",notificationSettings);        
    //register to receive notifications
    [application registerForRemoteNotifications];
} 

为什么?

1 个答案:

答案 0 :(得分:0)

从文档- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings此方法回调将在调用 - [UIApplication registerUserNotificationSettings:]时进行。用户授予应用程序的设置将作为第二个参数传入。这意味着,一旦我们获得用户权限(或者我们之前已经获得),那么此方法将调用,我们可以通过调用[application registerForRemoteNotifications]来注册应用程序以进行远程通知。