我没有收到推送通知到我的设备上。我已经获得了所有证书,我确实得到了测试推动。我发送推送的代码工作正常我可以在解析时看到。它还表示推送已发送但由于下面的代码没有推送到设备。
我在appdelegate中的代码didFinishLaunching方法提供警告以允许推送注释但没有通过
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[application registerUserNotificationSettings:notificationSettings];
} else {
[application registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
[application registerForRemoteNotifications];
}
如果我将此行[application registerForRemoteNotifications]
移到我的应用程序崩溃的任何地方。这条线是唯一的问题,如果我把它移动到任何地方,我已经尝试过它导致崩溃(应用程序根本不打开)。
帮我修复崩溃并获得推送通知吗?
答案 0 :(得分:0)
请你试试这个:
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert) categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
确保您在后台模式功能中有远程通知,并且在解析时没有任何密码上传.p12。
希望它对你有所帮助。