2017-03-26 33 views

回答

1

就实现你的AppDelegate的application(_ application:, didReceiveRemoteNotification userInfo:)userInfo是您的推送通知(包括有效负载)的JSON表示。

此外,您可以检查应用程序是“inactive”,至极的手段(在这种情况下),使用户只需通过此推送通知进来到App

示例代码:

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) { 
    if (UIApplication.shared.applicationState == .active) { 
     // you just got a PushNotification, but the app is running currently 
    } else if (UIApplication.shared.applicationState == .inactive) { 
     // Do your work in here, the User just opened the App via the Push Notification 
     // check userInfo for the Payload 
    } 
} 
+0

嘿谢谢你的答案。这有很大帮助。 '.active'部分完美地工作。然而,当我从'.inactive'或'.background'启动时,我想要的应用程序似乎不工作。 – ffritz

相关问题