我是靠谱客的博主 奋斗红酒,最近开发中收集的这篇文章主要介绍0912-从启动iOS的app的生命周期说起,Responding to the Launch of Your App必须清楚的前提知识点:,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

必须清楚的前提知识点:

1、All apps have an associated process, represented by the UIApplication object.   进程对应

        ---每一个app在ios系统中都有一个进程对应,而在这个进程就是用UIApplication object来表征。

       --whose job is to respond to important events happening within that process。

       --主要工作是与app重要的事件进行响应

2、When the user first launches your app on a device, the system displays your launch storyboard until your app is ready to display its UI.  默认提供启动闪屏

       - - 在启动你的app时,ios会主动提供一个launch storyboard来展示你公司的logo,图片这些,就是启动画面。为app的后台初始化运行争取时间,同时也是给一个用户错觉,以为自己启动得很快。 

  • Add views to your launch storyboard, and use Auto Layout constraints to size and position those views so that they adapt to the underlying environment. 

      --所以你可以在launch storyboard 中添加你的视图 

 

3、(重点)Put your app's launch-time initialization code in one or both of the following methods:    先行方法

  • application(_:willFinishLaunchingWithOptions:)  //还未就绪,准备阶段
  • application(_:didFinishLaunchingWithOptions:)  //已经就绪,随时可以运行

  --UIKit calls these methods at the beginning of your app’s launch cycle. Use them to:

  • Initialize your app's data structures.

  • Verify that your app has the resources it needs to run.

  --所以UIKit会先执行这两个方法(或其一),然后再初始化你的视图,你应该在这两个方法体能写你的初始化代码,资源, 数据什么的

  //其中的参数UIApplication.LaunchOptionsKey是Keys used to access values in the launch options dictionary passed to your app at initialization time. 字典类型中的一个元素,在初始化时间内,传递给你的app信息

使用示例:

class AppDelegate: UIResponder, UIApplicationDelegate,
CLLocationManagerDelegate {
let locationManager = CLLocationManager()
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions:
[UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// If launched because of new location data,
//
start the visits service right away.
if let keys = launchOptions?.keys {
if keys.contains(.location) {
locationManager.delegate = self
locationManager.startMonitoringVisits()
}
}
return true
}
// other methods…
}

 

 

遵守写代码约定,高效代码

1、Move Long-Running Tasks off the Main Thread。 去重就轻

--不要把你的繁重任务写在主线程内,主线程应该尽快展示页面,给用户的良好体验。所以你应该:

  • Defer the initialization of features that are not needed immediately.

      ---延迟你属性那些东西的初始化,除非这些东西立马要用到,不然就给我延迟初始化

  • Move important, long-running tasks off your app’s main thread. For example, run them asynchronously on a global dispatch queue.

     ---又长又臭的执行任务不要加到主线程中,可以挂在异步的全局的分发队列中

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

最后

以上就是奋斗红酒为你收集整理的0912-从启动iOS的app的生命周期说起,Responding to the Launch of Your App必须清楚的前提知识点:的全部内容,希望文章能够帮你解决0912-从启动iOS的app的生命周期说起,Responding to the Launch of Your App必须清楚的前提知识点:所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部