在didFinishLaunchingWithOptions

时间:2015-11-02 17:17:44

标签: ios swift parse-platform notifications

参数:iOS 9.1,iphone 5S,xcode 7.1,Swift 2,Parse SDK 1.9.0

我正在尝试捕获通过Parse发送的针对接收设备的所有状态的推送通知消息(即前景/后台/未加载/设备关闭)。对于所有情况,我的设备都会收到推送通知,但在某些情况下,有效负载/ userInfo字典不会到达。

适用于以下情况:

func application(application: UIApplication,  didReceiveRemoteNotification userInfo: [NSObject : AnyObject],  fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void)  
在AppDelegate中调用

(例如app in foreground),正确接收userInfo字典,我可以保存消息,发出通知&在适当的ViewController中显示它。

然而,

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
在AppDelegate中调用

(例如,如果关闭设备并且推送通知横幅是"刷过"打开应用程序),从语句中获取有效负载:

if let notificationPayload:NSDictionary = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary

始终为零,我无法完成与上述相同的操作。

产生推送的语句是:

push.setData(["alert" : message, "badge": "Increment", "content-available": NSNumber(integer: 1)])
push.sendPushInBackground() 

其中message是包含要显示的消息的String。

我已阅读过很多有关SO等的帖子。尝试了各种方法来解决这个问题,但无法找到解决方案。任何想法/帮助将不胜感激。如果有必要,我可以发布更多代码,但我基本上遵循Parse示例和标准方法。其他SO帖子。

RB

0 个答案:

没有答案