Ios Parse.com-设置从用户类到安装类的指针
嗨,我有一个应用程序,我已经设置了推送通知,他们正在工作。我的最后一步是,当用户打开应用程序并被询问是否允许推送通知时,我想设置一个从该用户到与该手机关联的安装id的指针。我可以用这个Ios Parse.com-设置从用户类到安装类的指针,ios,objective-c,parse-platform,push-notification,nsnull,Ios,Objective C,Parse Platform,Push Notification,Nsnull,嗨,我有一个应用程序,我已经设置了推送通知,他们正在工作。我的最后一步是,当用户打开应用程序并被询问是否允许推送通知时,我想设置一个从该用户到与该手机关联的安装id的指针。我可以用这个 PFInstallation *currentInstalation = [PFInstallation currentInstallation]; NSString *installationObjectId = currentInstalation.objectId; [currentUser setOb
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语句给出了以下错误
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Can't use nil for keys or values on PFObject. Use NSNull for values.'
应用程序失败了。是否有其他/更好的方法检查指针是否已设置,以便用户点击“不允许”,然后重新打开应用程序时不会退出
提前谢谢你的帮助,我真的很感激
编辑
应用程序DELAGTE代码
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吗谢谢这应该会有帮助
PFInstallation*currentInstallation=[PFInstallation-currentInstallation];
NSString*installationObjectId=CurrentInstallation.objectId;
[currentUser setObject:installationObjectId forKey:@“installationString”];
[currentUser setObject:currentInstalation forKey:@“安装”]代码>SWIFT:
var newUser = PFUser()
var currentInstallation = PFInstallation.currentInstallation()
let installationObjectId: NSString = currentInstallation.installationId
newUser.setObject(installationObjectId, forKey: "installationString")
newUser.setObject(currentInstallation, forKey: "installation")
newUser.saveInBackgroundWithBlock { (success, error) -> Void in
if error == nil {
print("success")
} else {
print(error)
}
}
我不知道你这样做的原因是否特定于你的应用程序,但我通常会在安装表中添加指向_User表的指针,这样设备本身就会链接到用户。我在选择“不允许”然后打开应用程序时没有遇到任何问题。我只是检查安装表中的列是否为null,如果为null,则将其设置为当前用户。你能在AppDelegate中发布处理通知的代码吗?AppDelegate中的前几行代码是什么方法?-(BOOL)application:(UIApplication*)application使用选项完成启动:(NSDictionary*)launchOptions
我相信如果你翻转指针的位置(在安装表而不是用户表中放置一个),您的问题将得到解决。不过,我可能误解了这个问题。@iKereIOrio如何在android中执行此操作