【问题标题】:App Installation not saved to Parse应用程序安装未保存到 Parse
【发布时间】:2015-11-08 17:22:43
【问题描述】:

我目前正在向我的 Parse 应用程序添加推送通知,并且需要使用 PFInstallation 注册每个设备才能这样做。我的应用程序已成功注册推送通知,当我第一次启动它时,它询问我是否想在设备上接收推送通知。第一次启动时,我在相应的AppDelegate.m方法中运行代码,如下:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    NSLog(@"Registered");
    // Store the deviceToken in the current installation and save it to Parse.
    PFInstallation *currentInstallation = [PFInstallation currentInstallation];
    [currentInstallation setDeviceTokenFromData:deviceToken];
    currentInstallation.channels = @[ @"global" ];
    [currentInstallation saveInBackground];
}

这应该已经使用PFInstallation 将我的设备保存到 Parse。但是,当我访问 Parse.com 并转到 Push 选项卡并查看“Audiences”下时,没有注册任何设备。我认为这可能是因为我的一些分发和开发证书,以及我的配置文件已经过时了。所以我更新了这些,并运行了另一段类似的代码来尝试保存PFInstallation

PFInstallation *currentInstallation = [PFInstallation currentInstallation];
currentInstallation.channels = @[ @"global" ];
[currentInstallation saveInBackground];

我在我的应用程序的 viewDidLoad 方法中运行了它,因为 AppDelegate.m 方法只会运行一次。但是,在我的 Parse 控制台中仍然没有看到 PFInstallation

为什么PFInstallation 没有被注册?我该如何解决这个问题?

感谢所有帮助。

【问题讨论】:

    标签: ios objective-c iphone parse-platform ios9


    【解决方案1】:

    这不是查找您保存的 PFInstallation 的地方。改为转到

    Core -> Data -> Installation
    

    查看它是否正确存储在表中。

    【讨论】:

    • 谢谢。安装选项卡最初没有显示,但现在我在 viewDidLoad 中运行了相同的代码。如何获取设备的 deviceToken,以便更新安装?此字段当前为空。
    • 我知道的唯一方法是通过 didRegisterForRemoteNotificationsWithDeviceToken 方法。您不应在 viewDidLoad 中处理此问题。要让您的 AppDelegate 再次触发,您可以注销当前用户并重新登录。
    猜你喜欢
    • 1970-01-01
    • 2016-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多