目前,我使用了相当多的空deviceToken字段。我发现这是因为在创建安装对象之前添加组有一个问题-它会阻止后续的创建工作。
我现在想做的是再次获取deviceToken并在解析器中更新它,但问题是,didRegisterForRemoteNotificationsWithDeviceToken在第一次之后再也不会运行了……
在初始调用didRegisterForRemoteNotificationsWithDeviceToken之后获取设备令牌的任何方法
发布于 2015-09-06 22:04:08
这确实适用于iOS 8:
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}发布于 2015-07-14 22:52:36
didRegisterForRemoteNotificationsWithDeviceToken可以重复调用。只需在didFinishLaunchingWithOptions方法中调用AppDelegate.m中的推送注册码即可。
下面是我的用法:
//Check for iOS 7 vs 8
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}就是这样--如果你每次都调用它,你会在每次加载时得到一个对didRegisterForRemoteNotificationsWithDeviceToken的委托回调。
https://stackoverflow.com/questions/31405193
复制相似问题