尝试使用 Parse.com 获取推送通知无法在设备上运行
Posted
技术标签:
【中文标题】尝试使用 Parse.com 获取推送通知无法在设备上运行【英文标题】:Trying to get push notifications using Parse.com not working on device 【发布时间】:2015-01-08 22:39:30 【问题描述】:所以我正在尝试 Parse.com 推送通知服务。
我已完成所有步骤等,当我尝试在模拟器上运行时,应用程序运行,但当我尝试在我的 Iphone 设备(Iphone 5s)上运行它时,应用程序崩溃并出现以下错误代码:
015-01-08 17:28:45.607 PickMeUp[451:60b] -[UIApplication registerForRemoteNotifications]:
unrecognized selector sent to instance 0x1576016f0
2015-01-08 17:28:45.610 PickMeUp[451:60b] *** Terminating app
due to uncaught exception 'NSInvalidArgumentException', reason:
'-[UIApplication registerForRemoteNotifications]: unrecognized selector sent to instance 0x1576016f0'
这是代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
// Override point for customization after application launch.
[Parse setApplicationId:@""];
// Register for Push Notitications
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings]; // The app crashes here
[application registerForRemoteNotifications];
return YES;
编辑
我的 iphone 没有完全更新。版本是 7.1
【问题讨论】:
【参考方案1】:试试这个
// Register for Push Notitications
if ([application respondsToSelector: @selector (registerUserNotificationSettings :)])
UIUserNotificationSettings * settings = [UIUserNotificationSettings settingsForTypes: UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound
categories: nil ];
[[UIApplication sharedApplication] registerUserNotificationSettings: settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
else
//ios7
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound];
【讨论】:
函数“选择器”的隐式声明在 C99 @TonyMkenu 中无效,并且:使用未声明的标识符“registerUserNotificationSettings”;你的意思是“UIUserNotificationSettings”吗? 抱歉,更新代码,打错了selector
- 必须是@selector
哇,它成功了,谢谢!你能解释一下它为什么起作用吗?另外,如果我想让它适用于 ios 6,那么我在哪里可以检查要写什么? @TonyMkenu
您可以在任何 iOS 版本中使用此代码,无需任何修改。 Tks【参考方案2】:
这对我不起作用,但它让我朝着正确的方向前进,经过几天的搜索,我找到了另一个堆栈链接: RegisterUserNotificationSettings is not working in ios 6.1 . 添加进去,一切都很好。
【讨论】:
这应该是一条评论。以上是关于尝试使用 Parse.com 获取推送通知无法在设备上运行的主要内容,如果未能解决你的问题,请参考以下文章
未在 android 中使用 parse.com 获取推送通知