iOS应用程序的状态

作者: Andy_Ron | 来源:发表于2017-07-07 21:00 被阅读135次
  • iOS应用程序一共有五种状态:
  • Not Running 程序还没运行
  • Inactive 程序运行在foreground但没有接收事件
  • Active 程序运行在foreground接收事件
  • Background 程序运行在background正在执行代码
  • Suspended 程序运行在background没有执行代码
  • iOS应用程序状态变化会回调APPDelegate中的方法,但不是每一种状态变化都会有对应的方法(上图的红框的两个变化就没有对应的方法)

    • application:didFinishLaunchingWithOptions: Not Running -> Inactive
    • applicationDidBecomeActive: Inactive -> Active
    • applicationWillResignActive: Active -> Inactive
    • applicationDidEnterBackground: Background -> Suspended
    • applicationWillEnterForeground: Background -> Inactive
    • applicationWillTerminate: Suspended -> Not Running
  • 常见的应用状态变化场景

    • 程序第一次启动(或者被杀掉以后启动):
      Not Running -> Inactive -> Active
    • 点击Home键(没有在Inof.plist中设置Application does not run in background):
      Active -> Inactive -> Background -> Suspended
    • 点击Home键(在Inof.plist中设置Application does not run in backgroundYES,应用不能运行在后台,进入后台后会立即进入Not Running):
      Active -> Inactive -> Background -> Suspended -> Not Running
    • 挂起重新运行
      Suspended -> Background -> Inactive -> Active
    • 内存清除(杀掉应用或删除应用)
      Suspended -> Not Running
    • 应用之间的切换
      Active -> Inactive
      Inactive -> Active
    • 点击Home键(在Inof.plist中设置Application does not run in backgroundYES,应用不能运行在后台,进入后台后会立即进入Not Running):
      Active -> Inactive -> Background -> Suspended -> Not Running
  • 可通过在APPDelegate的回调方法中打印数据,来查看应用状态变化

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        print("`application:didFinishLaunchingWithOptions:`  Not Running -> Inactive")
        return true
    }

    func applicationWillResignActive(_ application: UIApplication) {

        print("`applicationWillResignActive:`  Active -> Inactive")
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        
        print("`applicationDidEnterBackground:`  Background -> Suspended")
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        
        print("`applicationWillEnterForeground:` Background -> Inactive")
    }

    func applicationDidBecomeActive(_ application: UIApplication) {

        print("`applicationDidBecomeActive:`  Inactive -> Active")
    }

    func applicationWillTerminate(_ application: UIApplication) {

        print("`applicationWillTerminate:`  Suspended -> Not Running")
    }

欢迎您访问我的的微信公众号:欣欣向戎(微信号: andy_ron1587 )!

相关文章

  • iOS应用程序一般的五个状态

    一、iOS应用程序一般的五个状态(app的活动监测) 先说说iOS 应用程序5个状态: 停止运行-应用程序已经终止...

  • iOS应用程序状态

    iOS应用程序的生命周期是多种状态,各种状态之间可以互相切换,IOS的系统资源是有限的,应用程序在前台和后台的状态...

  • iOSAPP生命周期

    一、应用程序状态 iOS应用程序有一下几种状态 Not Running未运行应用程序尚未启动 Inactive未激...

  • 关于iOS的Push Notification的响应

    在说Push Notification的响应之前,先来讨论下iOS应用程序的状态,回调方法以及状态切换 应用程序的...

  • iOS App状态相关文章

    应用程序挂起、复原与终止— IOS开发 ios上的app运行状态的几种理解 iOS app状态及其多任务处理 io...

  • iOS应用程序的状态

    iOS应用程序一共有五种状态: Not Running 程序还没运行 Inactive ...

  • 应用程序生命周期

    16/08/04/wed iOS应用程序生命周期 应用程序的状态 Not running :未运行,程序没有启动...

  • 浅入浅出 iOS 应用程序的生命周期

    应用程序的生命周期 iOS 的应用程序主要由未运行、未激活、激活、后台、挂起这五个状态组成,每个状态具体的描述如下...

  • iOS 后台相关

    在iOS后台执行是本文要介绍的内容,大多数应用程序进入后台状态不久后转入暂停状态。在这种状态下,应用程序不执行任何...

  • iOS后台运行-实时定位

    1.先说说iOS 应用程序5个状态: 停止运行-应用程序已经终止,或者还未启动。 不活动-应用程序处于前台但不再接...

网友评论

    本文标题:iOS应用程序的状态

    本文链接:https://www.haomeiwen.com/subject/zuxrhxtx.html