为什么iOS静音推送触发应用程序:didFinishLaunchingWithOptions:当app在后台时

时间:2017-08-21 04:14:40

标签: ios background timeout launch silentpush

我在application:didFinishLaunchingWithOptions:方法中有一些15s超时的网络请求。我发现了以下奇怪的情况。

T1:app按主页按钮
进入后台 T2:应用程序收到静默推送并执行didFinishLaunchingWithOptions:方法,然后发送请求
T3(> T2 + 15s):用户点击应用图标。 T2中的所有请求都会立即超时。

我的问题是为什么didFinishLaunchingWithOptions在那种情况下被触发以及如何调试(重现这种情况,因为以上都在日志中)。

3 个答案:

答案 0 :(得分:0)

您可以检查应用状态,以确定应用是否在收到通知后从后台启动:

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

启动选项内部,并执行从通知启动应用程序时所需的任何工作。

答案 1 :(得分:0)

如果您的应用暂停或被杀,并且您收到了通知,则会调用{p> SELECT [DOCNAME],[DOCNUM],[EDITWHEN] as 'last edited date',[ENTRYWHEN] as 'created date', MAX (ACTIVITY_DATETIME) as 'last accessed date' FROM [Knowledge_Prod].[MHGROUP].[DOCMASTER] dm INNER JOIN [Knowledge_Prod].[MHGROUP].[DOCHISTORY] dh ON dm.DOCNUM = dh.DOCNUM WHERE dm.DOCNUM in ('10098776', '1355264') AND dh.ACTIVITY in ('View','Create','Copy', 'Checkin', 'Checkout','Print','Mail') GROUP BY [DOCNAME],[DOCNUM],[EDITWHEN],[ENTRYWHEN] 。您的应用程序可能已在后台崩溃,并且正在调用didFinishLaunchingWithOptions的方式。

要调试该方案,请执行以下操作。

  1. 点击目标并选择didFinishLaunchingWithOptions     enter image description here

  2. 选择启动至Edit Scheme enter image description here

  3. 运行该应用。

    enter image description here

  4. 现在,您可以在Wait for executable to be launched中添加断点并向您的设备发送通知。设备收到通知后,您可以进行调试。

答案 2 :(得分:0)

静默推送可以将挂起的应用程序(由于内存紧张而被iOS系统正确杀死,而不是用户手动杀死)到后台。在这种情况下,应用程序的生命周期变为:

  1. application:willFinishLaunchingWithOptions:
  2. application:didFinishLaunchingWithOptions:
  3. applicationDidEnterBackground:

苹果文档:About the Background Execution Sequence

相关问题