代码之家  ›  专栏  ›  技术社区  ›  xuning0

为什么iOS无声推送触发应用程序:DidFinishLaunchWithOptions:当应用程序在后台时

  •  0
  • xuning0  · 技术社区  · 9 年前

    我收到了一些网络请求,其中有15秒超时 application:didFinishLaunchingWithOptions:


    T2:应用程序收到静默推送并执行 didFinishLaunchingWithOptions:
    T3(>T2+15秒):用户点击应用程序图标。T2中的所有请求立即超时。

    didFinishLaunchingWithOptions 在这种情况下被触发,以及如何调试(复制这种情况,因为以上所有内容都在日志中)。

    3 回复  |  直到 9 年前
        1
  •  1
  •   Bilal hao zou    9 年前

    didFinishLaunchingWithOptions 如果你的应用程序被挂起或终止,并且你收到通知,则调用。你的应用程序可能在后台崩溃了,就是这样 正在呼叫。

    1. 单击目标并选择 Edit Scheme enter image description here

    2. 选择启动到 Wait for executable to be launched enter image description here

    3. 运行应用程序。

      enter image description here

    并向您的设备发送通知。一旦设备收到通知,您就可以进行调试。

        2
  •  0
  •   anomeric    9 年前

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

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

        3
  •  0
  •   xuning0    5 年前

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

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

    苹果文档: About the Background Execution Sequence