关于iOS8中用户接受推送通知(以及徽章等通知)的变化的两个问题 .
1) I am using the current approach which is working fine both on iOS7 and 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) I saw some people suggesting to ask for remote notifications in the following delegate
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
NSLog(@"registered for notifications settings %@",notificationSettings);
//register to receive notifications
[application registerForRemoteNotifications];
}
Why that ?
1 回答
From document ,
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
此方法回调将在调用时进行 -[UIApplication registerUserNotificationSettings:]
. 用户授予应用程序的设置将作为第二个参数传入 . 这意味着,一旦我们获得用户权限(或者如果我们之前已经获得),则此方法将调用,我们可以通过调用[application registerForRemoteNotifications]
来注册应用程序以进行远程通知 .