【问题标题】:Parse [PFInstallation currentInstallation] returns nil解析 [PFInstallation currentInstallation] 返回 nil
【发布时间】:2014-06-18 21:33:48
【问题描述】:

我目前无法让 Parse(推送通知服务)在现有 iOS 应用上运行。具体来说, [PFInstallation currentInstallation] 总是返回一个 nil 值。在我的didFinishLaunchingWithOptions 方法中我设置了

[Parse setApplicationId:parseAppID clientKey:parseClientKey];

然而,一旦我的applicationDidRegisterForRemoteNotificationsWithDeviceToken 方法被调用,下面的代码就会为currentInstallation 返回nil。

PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:_deviceToken];
[currentInstallation saveInBackground];

我不确定为什么在尝试将其合并到现有应用程序时会发生这种情况。我正在做与空白应用程序相同的事情,并且 Parse 在那里工作得很好。请注意,不会抛出任何错误。我只是在[PFInstallation currentInstallation] 上得到零回报,所以什么都没有保存。

任何帮助将不胜感激。

【问题讨论】:

    标签: ios objective-c push-notification parse-platform


    【解决方案1】:

    事实证明,如果您在 Parse Web 控制台上删除安装,就会发生这种情况。要修复它,您需要在手机上卸载并重新安装该应用程序,它应该会重新开始工作。

    【讨论】:

      【解决方案2】:

      您应该做的第一件事是使用“saveInBackgroundWithBlock”而不是“saveInBackouground”:

      [currentInstallation saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
         NSLog(@"success : %d  with error : %@",succeeded,error);
      }];
      

      这样,您将看到是否引发错误。

      此外,在application:didFinishLaunchingWithOptions: 方法中,您还应该调用

      if ([[UIApplication sharedApplication] enabledRemoteNotificationTypes] != UIRemoteNotificationTypeNone) {
        [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound];
      }
      

      以便每次启动应用程序时都会调用applicationDidRegisterForRemoteNotificationsWithDeviceToken 方法。

      最后,您应该确保已将这些库链接到您的应用程序:

      - AudioToolbox.framework  
      - CFNetwork.framework  
      - CoreGraphics.framework  
      - CoreLocation.framework  
      - libz.dylib  
      - MobileCoreServices.framework  
      - QuartzCore.framework  
      - Security.framework  
      - StoreKit.framework  
      - SystemConfiguration.framework 
      

      【讨论】:

      • 德里科,感谢您的帮助。我确实已经让我的应用程序注册了不同的通知类型。而且我认为我的问题在原始问题中并不明确。调用 [PFInstallation currentInstallation] 总是返回 nil。因此,虽然我确实在 saveInBackground 上遇到错误,但我认为这不是问题所在。获取当前安装有问题。我确实将所有库都附加到我的应用程序中
      • 哦,好吧,我错了。然后,如果你在 didFinishLaunching 方法中尝试这个会发生什么: [Parse setApplicationId:parseAppID clientKey:parseClientKey]; NSLog(@"%@",[PFInstallation currentInstallation]);//注册后直接
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-21
      • 1970-01-01
      相关资源
      最近更新 更多