当iOS应用程序被挂起/终止且用户单击通知时,如何处理Firebase推送通知?
我想知道当我的应用程序被挂起/终止时,应该回调什么函数,或者何时收到通知。当我的应用程序处于前台/后台时,我可以处理,但是当应用程序被终止时,我不确定如何以及在哪里处理或解析我的通知负载?在通知打开的应用程序上,您将在应用程序中获得通知数据:将调用didFinishedLaunchingWithOptions方法当iOS应用程序被挂起/终止且用户单击通知时,如何处理Firebase推送通知?,ios,swift,firebase,push-notification,Ios,Swift,Firebase,Push Notification,我想知道当我的应用程序被挂起/终止时,应该回调什么函数,或者何时收到通知。当我的应用程序处于前台/后台时,我可以处理,但是当应用程序被终止时,我不确定如何以及在哪里处理或解析我的通知负载?在通知打开的应用程序上,您将在应用程序中获得通知数据:将调用didFinishedLaunchingWithOptions方法 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (launchOptions != nil)
{
// opened from a push notification when the app is closed
NSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo != nil)
{
NSLog(@"userInfo->%@", [userInfo objectForKey:@"aps"]);
}
}
else
{
// opened app without a push notification.
}
}
Swift 5.1
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
if launchOptions != nil {
// opened from a push notification when the app is closed
let userInfo = launchOptions?[.remoteNotification] as? [AnyHashable : Any]
if userInfo != nil {
if let object = userInfo?["aps"] {
print("userInfo->\(object)")
}
}
} else {
// opened app without a push notification.
}
}
用Swift怎么样?现在我需要从appdelegate演示和演示一个Viewcontroller。如何实现这一点?您可以使用ApplicationLegate.window.rootviewcontroller演示viewcontroller