![](/img/trans.png)
[英]Silent iOS Push Notification with React Native when app is in background
[英]Why iOS silent push triggers application:didFinishLaunchingWithOptions: when app is in background
我在application:didFinishLaunchingWithOptions:
方法中有一些超時 15 秒的網絡請求。 我發現了以下奇怪的情況。
T1:應用按home鍵進入后台
T2:app收到靜默推送並執行didFinishLaunchingWithOptions:
方法,然后發送請求
T3(> T2 + 15s):用戶點擊應用圖標。 T2 中的所有請求都立即超時。
我的問題是為什么在這種情況下觸發了didFinishLaunchingWithOptions
以及如何調試(重現這種情況,因為以上所有內容都在日志中)。
您可以檢查應用程序狀態以確定應用程序在收到通知時是否從后台啟動:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
if ( application.applicationState == UIApplicationStateInactive || application.applicationState == UIApplicationStateBackground ) {
//opened from a push notification when the app was on background
}
}
編輯::
這里沒有什么可調試的,它是預期的功能。
如果你想以不同的方式處理它,你可以尋找
UIApplicationLaunchOptionsLocalNotificationKey
在啟動選項內,並在從通知啟動應用程序時執行您需要的任何工作。
靜默推送可以將掛起的應用程序(由於內存緊張而被iOS系統正確殺死,而不是用戶手動殺死)到后台。 在這種情況下,應用程序的生命周期變為:
application:willFinishLaunchingWithOptions:
application:didFinishLaunchingWithOptions:
applicationDidEnterBackground:
Apple 文檔: 關於后台執行序列
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.