registerForRemoteNotificationTypes不能正常工作iOS7 xcode 6

registerForRemoteNotificationTypes不能正常工作iOS7 xcode 6,第1张

概述升级我们的应用程序以使用iOS 8后出现问题,其中registerForRemoteNotificationTypes似乎无法在运行iOS 7的手机上运行,​​因为didRegisterForRemoteNotificationsWithDeviceToken没有被调用,并且“允许推送通知”对话框没有出现在应用程序上.这是我正在使用的代码 // Add registration for remot 升级我们的应用程序以使用iOS 8后出现问题,其中registerForRemoteNotificationTypes似乎无法在运行iOS 7的手机上运行,​​因为dIDRegisterForRemoteNotificationsWithDevicetoken没有被调用,并且“允许推送通知”对话框没有出现在应用程序上.这是我正在使用的代码

// Add registration for remote notificationsif ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {    NSLog(@"iOS 8 Registering for remote notification");    UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categorIEs:nil];    [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];    [[UIApplication sharedApplication] registerForRemoteNotifications];} else {    NSLog(@"Registering for remote notification");    [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];}

此代码适用于运行iOS 8的手机,而不适用于iOS 7.
另外一点信息我们设法通过连接手机的xcode运行应用程序后,推送通知才能在iOS 7手机上运行.然后,我们将与广告Hoc部署相同的代码部署到运行iOS 7的另一部iPhone和iPad,但两者均无效.
有什么明显的东西我在这里失踪了.

解决方法 试试这个代码,可能适合你.

-(BOol)application:(UIApplication *)application dIDFinishLaunchingWithOptions:(NSDictionary   *)launchOptions{if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]){// iOS 8 Notifications[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categorIEs:nil]];[application registerForRemoteNotifications];}else{// iOS < 8 Notifications[application registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];}return YES;}
总结

以上是内存溢出为你收集整理的registerForRemoteNotificationTypes不能正常工作iOS7 xcode 6全部内容,希望文章能够帮你解决registerForRemoteNotificationTypes不能正常工作iOS7 xcode 6所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1024650.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存