推送通知无法正常工作
Push notifications are not working properly
我和我的团队因为这个问题遭受了一个月的痛苦,问题是苹果推送通知在所有已安装的设备上工作了一段时间,但在那之后甚至一台设备也没有收到任何通知,请持续发生这种情况解决这个问题。那个问题在哪里以及如何解决这个问题,请帮助我。我在 AppDelegate
的 didFinishLaunchingWithOptions
方法中写了下面的代码
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
如果你想注册 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];
}
我和我的团队因为这个问题遭受了一个月的痛苦,问题是苹果推送通知在所有已安装的设备上工作了一段时间,但在那之后甚至一台设备也没有收到任何通知,请持续发生这种情况解决这个问题。那个问题在哪里以及如何解决这个问题,请帮助我。我在 AppDelegate
didFinishLaunchingWithOptions
方法中写了下面的代码
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
如果你想注册 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];
}