我在AppDelegate中使用didReceiveRemoteNotification
方法进行推送通知,但是当应用程序不处于后台状态时,我似乎无法弄清楚如何让它们正常工作。我在这里发现了很多问题,这些问题解释了我在下面尝试过的东西。
如果有数据,我会继续回忆didReceiveRemoteNotification
的逻辑。
问题是这不起作用,而且我也不知道如何调试这个以使应用程序进入这个状态,这将被称为松散日志。
if let remoteNotification = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? [NSObject : AnyObject] {
print(remoteNotification)
self.application(application, didReceiveRemoteNotification: remoteNotification)
}
// This method is working fine
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
if (application.applicationState == UIApplicationState.Active) {
print("active don't do anything")
} else {
let notif = JSON(userInfo)
if notif["vc"] != nil {
NSNotificationCenter.defaultCenter().postNotificationName("handleNotification", object: nil, userInfo: userInfo as [NSObject : AnyObject])
}
}
}