【发布时间】:2014-11-12 14:40:05
【问题描述】:
我最近将我的一部测试 iPhone 升级到了 iOS 8,然后升级了 PUSH 注册码 如下(使用 xCode 6)
-(BOOL)hasNotificationsEnabled {
NSString *iOSversion = [[UIDevice currentDevice] systemVersion];
NSString *prefix = [[iOSversion componentsSeparatedByString:@"."] firstObject];
float versionVal = [prefix floatValue];
if (versionVal >= 8)
{
NSLog(@"%@", [[UIApplication sharedApplication] currentUserNotificationSettings]);
//The output of this log shows that the app is registered for PUSH so should receive them
if ([[UIApplication sharedApplication] currentUserNotificationSettings].types != UIUserNotificationTypeNone) {
return YES;
}
}
else
{
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types != UIRemoteNotificationTypeNone){
return YES;
}
}
return NO;
}
-(void)registerForPUSHNotifications {
NSString *iOSversion = [[UIDevice currentDevice] systemVersion];
NSString *prefix = [[iOSversion componentsSeparatedByString:@"."] firstObject];
float versionVal = [prefix floatValue];
if (versionVal >= 8)
{
//for iOS8
UIUserNotificationSettings *settings =
[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
}
尽管进行了此次升级,并且 [[UIApplication sharedApplication] currentUserNotificationSettings] 显示设备已启用 PUSH,但我没有收到 PUSH 通知。
我正在使用 Parse 并按照他们所关心的 (https://parse.com/tutorials/ios-push-notifications) 做所有事情。
有人遇到同样的问题吗?还有什么我可能会错过的吗?
【问题讨论】:
-
查看用于注册推送通知的代码会很有帮助,因为 iOS 8 的 API 已更改。请参阅此处:stackoverflow.com/questions/24049266/…
-
什么意思?代码在那里..
-
哦,奇怪。我没有看到下面有更多代码。我的错。
-
只要确保您没有将测试应用程序与生产服务器一起使用。在 iOS 开发 4 年后,我仍然陷入这个陷阱。
-
这个链接对我有用..!stackoverflow.com/questions/4086599/…
标签: ios iphone notifications parse-platform push