推送通知无法正常工作

时间:2015-01-11 12:54:48

标签: ios ios7 ios8 push-notification apple-push-notifications

我和我的团队因为这个问题而遭受了一个月的困扰,问题是苹果推送通知在所有安装的设备上都工作了一段时间,但在那之后即使一台设备也没有收到任何通知,这种情况不断发生请解决这个问题问题。这个问题在哪里以及如何解决这个问题,请帮助我。我已在didFinishLaunchingWithOptions

AppDelegate方法中编写了以下代码
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];

1 个答案:

答案 0 :(得分:1)

如果您想注册iOS 8,iOS 7需要在didFinishLaunchingWithOptions中注册:

if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])
{
    // iOS 8 Notifications
    // use registerUserNotificationSettings
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
    // iOS < 8 Notifications
    // use registerForRemoteNotifications
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];
}