您好我有一个应用程序,我已设置了推送通知,他们正在工作。我的最后一步是当用户打开应用程序并询问他们是否允许推送通知时,我想将该用户的指针设置为与该手机关联的安装ID。我可以用这个
来做到这一点 PFInstallation *currentInstalation = [PFInstallation currentInstallation];
NSString *installationObjectId = currentInstalation.objectId;
[currentUser setObject:installationObjectId forKey:@"installationString"];
[currentUser setObject:currentInstalation forKey:@"installation"];
以下是我的用户类部分的图片,以澄清
但我不希望每次用户打开应用程序时都进行此保存,如果尚未设置,我只想做一次。所以我打算用这个if语句检查它是否已经设置
if (![currentUser[@"installationString"] isEqual:installationObjectId]) {
//save it here
}
但问题是,如果用户点击“不允许推送通知”,因为没有设置安装对象,因此该电话/用户的安装对象为空,上面的if语句给出了以下错误< / p>
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Can't use nil for keys or values on PFObject. Use NSNull for values.'
该应用程序失败。是否有其他/更好的方法来检查指针是否已设置,以便如果用户点击“不允许”然后重新打开应用程序它将不会退出。
感谢您的帮助,我非常感谢!!!
修改
APP DELAGTE CODE
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
} else {
// Register for Push Notifications before iOS 8
[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound)];
}
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Store the deviceToken in the current installation and save it to Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
[currentInstallation saveInBackground];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[PFPush handlePush:userInfo];
}
我已经设置了这种方式,因为我有一个云功能,可以向用户发送推送,并从用户获取指针到安装ID以发送推送,也许我可以考虑翻转它?
如果用户点击不允许。 Parse.com不会保存该设备的安装ID吗?
由于
答案 0 :(得分:1)
这应该有助PFInstallation *currentInstalation = [PFInstallation currentInstallation];
NSString *installationObjectId = currentInstalation.objectId;
[currentUser setObject:installationObjectId forKey:@"installationString"];
[currentUser setObject:currentInstalation forKey:@"installation"];
答案 1 :(得分:0)
SWIFT:
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:907)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextLong(Scanner.java:2265)
at java.util.Scanner.nextLong(Scanner.java:2225)
at Solution.main(Solution.java:23)