![](/img/trans.png)
[英]Update Parse Installation objects using REST and only have deviceToken
[英]Update Parse deviceToken AFTER registration
目前,我坐着很多空的deviceToken字段。 我发现这是因为在创建安装对象之前添加组存在问题-它会阻止后续的创建工作。
我现在想做的是再次获取该deviceToken并在Parse中对其进行更新,但问题是, didRegisterForRemoteNotificationsWithDeviceToken
在第一次之后就再也不会运行了……
以任何方式在对didRegisterForRemoteNotificationsWithDeviceToken
的初始调用之后获取设备令牌?
这确实适用于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)];
}
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
的委托回调。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.