3

我在我的应用程序中使用了 easyapns 推送服务。Push 在 iOS 8 上运行良好,但我的客户说 Push 在 iPhone 6 上不起作用。我没有 iPhone 6 可以检查。其他人会遇到同样的问题。什么可能出错?

4

1 回答 1

2

这是我为 iOS 8 和 iPHONE 6/6+ 所做的工作。iOS 8 改变了推送通知注册的工作方式。以下代码将允许设备在 iOS 8 和 iOS 8 之前的设备上注册推送通知。

将此代码放在您的 appDelegate.m 中的 didFinishLaunchingWithOptions 中:

#ifdef __IPHONE_8_0
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}  else {
    UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
}
#else

UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];

#endif

此外,将此作为新方法添加到您的 appDelegate.m

#ifdef __IPHONE_8_0
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    [application registerForRemoteNotifications];
}
#endif

让我知道它是如何工作的。

于 2014-10-10T18:08:50.290 回答