【问题标题】:iOS Push Notifications Working on iOS 8 But Not on iOS 7 in iOS SDK 8.1iOS 推送通知适用于 iOS 8,但不适用于 iOS SDK 8.1 中的 iOS 7
【发布时间】:2015-01-01 13:06:51
【问题描述】:
if([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
[self registerForiOS8PushSettings]; //for iOS8
} else {
//iOS7 or earlier
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
无法获取到 iOS7 设备的推送通知。 didRegisterForRemoteNotificatiosnWithDeviceToken 被调用,实际上消息已成功传递。在 iOS8 中运行良好。
【问题讨论】:
标签:
ios
iphone
ios7
push-notification
【解决方案1】:
在 iOS8 中,流程发生了变化。要让您的应用注册 iOS8 和早期版本,请执行以下操作:
-(void)registerAppForNotifications{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeNewsstandContentAvailability| UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
}