gpt4 book ai didi

ios - Parse.com - 将指针从用户类设置为安装类

转载 作者:行者123 更新时间:2023-11-29 02:37:58 25 4
gpt4 key购买 nike

您好,我有一个应用程序,我已经设置了推送通知并且它们正在运行。我的最后一步是,当用户打开应用程序并询问他们是否要允许推送通知时,我想设置一个从该用户到与该手机关联的安装 ID 的指针。我可以用这个来做到这一点

 PFInstallation *currentInstalation = [PFInstallation currentInstallation];
NSString *installationObjectId = currentInstalation.objectId;
[currentUser setObject:installationObjectId forKey:@"installationString"];
[currentUser setObject:currentInstalation forKey:@"installation"];

这是我的用户类的一部分的图片以澄清

enter image description here

但我不想在每次用户打开应用程序时都保存,我只想在尚未设置时保存一次。所以我打算使用这个 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.'

应用程序失败了。是否有另一种/更好的方法来检查指针是否已设置,以便如果用户点击“不允许”然后重新打开应用程序,它不会退出。

提前感谢您的帮助,我真的很感激!!!

编辑

应用程序删除代码

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 *currentInstalation = [PFInstallation currentInstallation];
NSString *installationObjectId = currentInstalation.objectId;
[currentUser setObject:installationObjectId forKey:@"installationString"];
[currentUser setObject:currentInstalation forKey:@"installation"];

关于ios - Parse.com - 将指针从用户类设置为安装类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26147132/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com