WatchOS系统开发大全(4)-WatchApp生命周期

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013263917/article/details/76199033

WatchOSAPP生命周期

1.1-简介

  • WatchOS2.0之后的工程与WatchOS1.0的工程有什么不同之处?

    • 创建的方式不同

    • 2.0的工程多了一个文件:ExtensionDelegate


0700.png
  • ExtensionDelegate文件是干嘛用的?

    • 用于管理应用的生命周期(能够独立运行)
  • WatchOS1.0没有应用的生命周期,只有WKInterfaceController的生命周期

  • Controller的生命周期和应用的生命周期有什么区别?

    • controller的生命周期是管理每一个界面的生命周期

    • 应用的生命周期是管理整个App的生命周期

1.2-API

    //应用加载时会调用
    func applicationDidFinishLaunching() {
        // Perform any final initialization of your application.
        print(__FUNCTION__)
    }

    //应用激活时会调用(进入前台)
    func applicationDidBecomeActive() {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
        print(__FUNCTION__)
    }

    //应用失活时会调用(退到后台)
    func applicationWillResignActive() {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, etc.
        print(__FUNCTION__)
    }
  • WatchApp的生命周期没有iPhoneApp的生命周期那么复杂,只有三个方法
展开阅读全文

没有更多推荐了,返回首页