簡體   English   中英

當 iOS 應用程序被暫停/殺死並且用戶點擊通知時,如何處理 Firebase 推送通知?

[英]How to handle Firebase push notification when iOS app is suspended/killed and user clicks on the notification?

我想知道應該回調什么 function 或者當我的應用程序暫停/終止時收到通知時。 當我的應用程序處於前台/后台時,我能夠處理,但是當應用程序被殺死時,我不確定如何以及在哪里處理或解析我的通知有效負載?

從通知打開應用程序時,您將在 application:didFinishedLaunchingWithOptions 方法中獲取通知數據。

- (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.
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM