解析推送通知测试 PFInstallation 不工作

Parse Push Notifications Testing PFInstallation Not Working

我是一名 objective c 编码员,试图在解析中使用推送通知。

我在 appDelegate.m 文件的 didFinishLaunchingWithOptions 部分添加了 Parse setApplicationID 和客户端密钥。然后我添加了这两个方法:

- (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.badge = 0;
NSArray *channels = [NSArray arrayWithObjects:@"global", [DataSource sharedInstance].userProfile.userID, nil];
[currentInstallation addObjectsFromArray:channels forKey:@"channels"];
[currentInstallation saveInBackground];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[PFPush handlePush:userInfo];
}

每当 currentInstallation.badge 号码发生变化时,应用程序上的徽章号码都会响应,当我断点代码时,它会显示频道已添加到 currentInstallation。

问题是当前安装没有保存在 Parse 数据库的核心安装对象部分。我添加到 currentInstallation 的频道在 saveInBackground 有 运行.

后没有出现

在调试问题时,我删除了核心安装数据库中与我用于测试的设备对应的行(这是核心安装数据库中的唯一对象)。当我重新运行 代码时,没有添加任何内容。

还有一条信息是,我非常确定我正确地完成了所有设置,因为在设置完所有内容后,我能够在我的设备上接收测试推送通知。问题是我无法以编程方式更改我的测试设备在核心安装数据库上订阅的频道。

所以基本上我的问题是:如何使用 PFInstallation saveInBackground 将项目写入核心安装数据库?我做错了什么?

感谢您的帮助!非常感谢!

编辑 现在,还有一个问题是我无法将我正在测试推送通知的设备添加回我的核心安装对象数据库,因此我在数据库中的对象数仍为 0。关于如何找回它有什么建议吗?

这太令人沮丧了。我所要做的就是注销我的 Parse 帐户,然后重新登录。瞧!频道在那里!