主頁 > 移動端開發 > 【iOS翻譯】App啟動時的回應程序

【iOS翻譯】App啟動時的回應程序

2020-09-11 20:58:19 移動端開發

 Responding to the Launch of Your App

  Initialize your app’s data structures, prepare your app to run, and respond to any launch-time requests from the system.

  初始化應用程式的資料結構、準備運行應用程式、回應系統啟動時的一些請求,

 Overview 

  The system launches your app when the user taps your app’s icon on the Home screen. If your app requested specific events, the system might also launch your app in the background to handle those events. For a scene-based app, the system similarly launches the app when one of your scenes needs to appear onscreen or do some work.

  當用戶點擊桌面的應用程式圖示時,系統就會運行你的應用程式,如果你的應用程式請求特定的事件,系統可能會在后臺進行處理這些事件,而對于一個基于場景的應用程式,當一個場景需要出現在螢屏上或者做一些作業時,系統也會啟動應用程式,

  All apps have an associated process, represented by the UIApplication object. Apps also have an app delegate object—an object that conforms to the UIApplicationDelegateprotocol—whose job is to respond to important events happening within that process. Even a scene-based app uses an app delegate to manage fundamental events like launch and termination. At launch time, UIKit automatically creates the UIApplication object and your app delegate. It then starts your app’s main event loop.

  所有的應用程式都有一個關聯的行程,由UIApplication物件標識,應用程式也有一個委托物件(一個基于UIApplicationDelegate協議的物件,它的作業時回應行程執行中的重要事件),甚至一個基于場景的應用程式也使用應用程式委托物件來管理基本事件,在啟動時,UIKit會自動創建UIApplication物件和委托代理,然后啟動應用程式的主事件回圈,

 Provide a Launch Storyboard

  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. Displaying the launch storyboard assures the user that your app launched and is doing something. If your app initializes itself and readies its UI quickly, the user may see your launch storyboard only briefly.

  當用戶第一次在設備上啟動你的應用程式時,系統會顯示啟動故事板,直到程式準備好它的UI.顯示故事板的目的是向用戶保證你的應用程式已經啟動,而且正在運行, 如果你的應用程式初始化的速度和準備的程序非常快,那用戶可能只能短暫的看到你的啟動故事板,

  Xcode projects automatically include a default launch storyboard for you to customize, and you can add more launch storyboards as needed. To add new launch storyboards to your project, do the following:

  Xcode專案會自動包含一個默認的啟動故事板,但你可以根據需要添加更多的故事板,如果想添加新的啟動故事板到專案中,需要做如下操作:

  1. Open your project in Xcode.

  2. Select File > New > New File.

  3. Add a Launch Screen resource to your project.

  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. For example, you might create a splash screen with a solid-color background and a fixed-size image of your company logo or other content. Always create a final version of the interface you want. Never include temporary content or content that requires localization. UIKit displays exactly what you provide, using your constraints to fit your views into the available space.

  添加視圖到啟動故事板中,使用自動布局約束來調整視圖的大小和位置,以適應底層的環境,例如:你可以創建一個純色的背景和固定大小的圖片來標識你的公司logo,或者其他內容,始終創建所需介面的最終版本,不要包含臨時內容或需要本地化的內容,精確地顯示你所提供的,使用你的約束來講你的視圖放入可用的空間,

 Important

  In iOS 13 and later, always provide a launch storyboard for your app. Don’t use static launch images.

  在iOS13及以后,總是提供一個故事板,不再使用靜態的啟動圖片,

  Initialize Your App's Data Structures

  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:

  UIKit在應用程式啟動周期開始時呼叫這些方法,使用它們來做以下操作:

  • Initialize your app's data structures.

  • 初始化應用程式的結構
  • Verify that your app has the resources it needs to run. 

  • 驗證應用程式運行所需要的資源
  • Perform any one-time setup when your app is launched for the first time. For example, install templates or user-modifiable files in a writable directory; see Performing One-Time Setup for Your App. 

  • 在應用程式第一次啟動時執行任何一次性設定,例如:在可讀寫的目錄中安裝模板或用戶可修改的檔案,
  • Connect to any critical services that your app uses. For example, connect to the Apple Push Notification service if your app supports remote notifications.

  • 連接應用程式使用的任何關鍵服務,例如:如果你的應用程式支持遠程推送通知,會連接到APNS.
  • Check the launch options dictionary for information about why your app was launched; see Determine Why Your App Was Launched.

  • 檢查啟動項字典資訊,

  For apps that aren't scene-based, UIKit loads your default user interface automatically at launch time. Use the application(_:didFinishLaunchingWithOptions:) method to make additional changes to that interface before it appears onscreen. For example, you might install a different view controller to reflect what the user was doing the last time they used the app.

  對于不是基于場景的應用,UIKit在啟動時默認加載用戶界面,使用application(_:didFinishLaunchingWithOptions:)方法來欄位外的更改,例如:你可以安裝一個默認控制器來反應用戶上一次使用應用程式做什么,

  Move Long-Running Tasks off the Main Thread

  When the user launches your app, make a good impression by launching quickly. UIKit doesn't present your app's interface until after the application(_:didFinishLaunchingWithOptions:) method returns. Performing long-running tasks in that method or your application(_:willFinishLaunchingWithOptions:) method might make your app appear sluggish to the user. Returning quickly is also important when launching to the background, because your app’s background execution time is limited. 

  當用戶啟動應用程式時,通過快速啟動來給用戶留下一個好的印象,UIKit直到應用程式(_:didFinishLaunchingWithOptions:)方法回傳后,才會顯示用戶界面,在該方法或(_:willFinishLaunchingWithOptions:)方法中執行耗時操作,可能會讓用戶覺得你的應用程式運行緩慢,在啟動到后臺時,快速回傳很重要,因為應用程式在后臺執行時間有限,

  Move tasks that are not critical to your app’s initialization out of the launch-time sequence. For example:

  將對應用程式啟動不重要的任務移出啟動時間序列,例如:

  • 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.

  • 將重要的長時間運行的任務移出應用程式的主執行緒,例如:在全域調度佇列中異步運行他們,

 Determine Why Your App Was Launched

  When UIKit launches your app, it passes along a launch options dictionary to your application(_:willFinishLaunchingWithOptions:) and application(_:didFinishLaunchingWithOptions:) methods with information about why your app was launched. The keys in that dictionary indicate important tasks to perform immediately. For example, they might reflect actions that the user started elsewhere and want to continue in your app. Always check the contents of the launch options dictionary for keys that you expect, and respond appropriately to their presence.

  當UIkit啟動你的應用程式時,它會傳遞一個啟動項字典給你的應用程式application(_:willFinishLaunchingWithOptions:) and application(_:didFinishLaunchingWithOptions:)方法,其中包含了為什么啟動,字典中的鍵標識立即執行的重要任務,例如:它們可能反應用戶在其他地方啟動的操作,并希望在應用程式中繼續執行,始終檢查啟動項字典的內容,查找您期望的鍵,并對它們做出適當的回應,

 Note

  For a scene-based app, examine the options passed to the application(_:configurationForConnecting:options:) method to determine why your scene was created.

  對于基于場景的應用程式,檢查傳遞給應用程式(_:configurationforconnected:options:)方法的選項,以確定為什么創建場景,

  Listing 1 shows the app delegate method for an app that handles background location updates. When the location key is present, the app starts location updates immediately, instead of deferring them until later. Starting location updates allows the Core Location framework to deliver the new location event.

  清單1顯示了處理后臺位置更新的應用程式的應用程式委托方法,當位置鍵存在時,應用程式立即啟動位置更新,而不是推遲到以后,啟動位置更新允許核心位置框架交付新的位置事件,

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…}

  The system doesn’t include a key unless your app supports the corresponding feature. For example, the system doesn’t include the remoteNotification key for an app that doesn’t support remote notifications. 

  For a list of launch option keys and information about how to handle them, see UIApplication.LaunchOptionsKey.

  除非你的應用程式支持相應的功能,否則系統不會包含密鑰,例如,對于不支持遠程通知的應用程式,系統不包含remoteNotification鍵,
  有關啟動選項鍵的串列和有關如何處理它們的資訊,請參見UIApplication.LaunchOptionsKey,

 

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/7509.html

標籤:iOS

上一篇:iOS 裁剪工具

下一篇:【iOS翻譯】對UIGestureRecognizer多種手勢傻傻分不清

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【從零開始擼一個App】Dagger2

    Dagger2是一個IOC框架,一般用于Android平臺,第一次接觸的朋友,一定會被搞得暈頭轉向。它延續了Java平臺Spring框架代碼碎片化,注解滿天飛的傳統。嘗試將各處代碼片段串聯起來,理清思緒,真不是件容易的事。更不用說還有各版本細微的差別。 與Spring不同的是,Spring是通過反射 ......

    uj5u.com 2020-09-10 06:57:59 more
  • Flutter Weekly Issue 66

    新聞 Flutter 季度調研結果分享 教程 Flutter+FaaS一體化任務編排的思考與設計 詳解Dart中如何通過注解生成代碼 GitHub 用對了嗎?Flutter 團隊分享如何管理大型開源專案 插件 flutter-bubble-tab-indicator A Flutter librar ......

    uj5u.com 2020-09-10 06:58:52 more
  • Proguard 常用規則

    介紹 Proguard 入口,如何查看輸出,如何使用 keep 設定入口以及使用實體,如何配置壓縮,混淆,校驗等規則。

    ......

    uj5u.com 2020-09-10 06:59:00 more
  • Android 開發技術周報 Issue#292

    新聞 Android即將獲得類AirDrop功能:可向附近設備快速分享檔案 谷歌為安卓檔案管理應用引入可安全隱藏資料的Safe Folder功能 Android TV新主界面將顯示電影、電視節目和應用推薦內容 泄露的Android檔案暗示了傳說中的谷歌Pixel 5a與折疊屏新機 谷歌發布Andro ......

    uj5u.com 2020-09-10 07:00:37 more
  • AutoFitTextureView Error inflating class

    報錯: Binary XML file line #0: Binary XML file line #0: Error inflating class xxx.AutoFitTextureView 解決: <com.example.testy2.AutoFitTextureView android: ......

    uj5u.com 2020-09-10 07:00:41 more
  • 根據Uri,Cursor沒有獲取到對應的屬性

    Android: 背景:呼叫攝像頭,拍攝視頻,指定保存的地址,但是回傳的Cursor檔案,只有名稱和大小的屬性,沒有其他諸如時長,連ID屬性都沒有 使用 cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATIO ......

    uj5u.com 2020-09-10 07:00:44 more
  • Android連載29-持久化技術

    一、持久化技術 我們平時所使用的APP產生的資料,在記憶體中都是瞬時的,會隨著斷電、關機等丟失資料,因此android系統采用了持久化技術,用于存盤這些“瞬時”資料 持久化技術包括:檔案存盤、SharedPreference存盤以及資料庫存盤,還有更復雜的SD卡記憶體儲。 二、檔案存盤 最基本存盤方式, ......

    uj5u.com 2020-09-10 07:00:47 more
  • Android Camera2Video整合到自己專案里

    背景: Android專案里呼叫攝像頭拍攝視頻,原本使用的 MediaStore.ACTION_VIDEO_CAPTURE, 后來因專案需要,改成了camera2 1.Camera2Video 官方demo有點問題,下載后,不能直接整合到專案 問題1.多次拍攝視頻崩潰 問題2.雙擊record按鈕, ......

    uj5u.com 2020-09-10 07:00:50 more
  • Android 開發技術周報 Issue#293

    新聞 谷歌為Android TV開發者提供多種新功能 Android 11將自動填表功能整合到鍵盤輸入建議中 谷歌宣布Android Auto即將支持更多的導航和數字停車應用 谷歌Pixel 5只有XL版本 搭載驍龍765G且將比Pixel 4更便宜 [圖]Wear OS將迎來重磅更新:應用啟動時間 ......

    uj5u.com 2020-09-10 07:01:38 more
  • 海豚星空掃碼投屏 Android 接收端 SDK 集成 六步驟

    掃碼投屏,開放網路,獨占設備,不需要額外下載軟體,微信掃碼,發現設備。支持標準DLNA協議,支持倍速播放。視頻,音頻,圖片投屏。好點意思。還支持自定義基于 DLNA 擴展的操作動作。好像要收費,沒體驗。 這里簡單記錄一下集成程序。 一 跟目錄的build.gradle添加私有mevan倉庫 mave ......

    uj5u.com 2020-09-10 07:01:43 more
最新发布
  • 歡迎頁輪播影片

    如圖,引導開始,球從上落下,同時淡入文字,然后文字開始輪播,最后一頁時停止,點擊進入首頁。 在來看看效果圖。 重力球先不講,主要歡迎輪播簡單實作 首先新建一個類 TextTranslationXGuideView,用于影片展示 文本是類似的,最后會有個圖片箭頭影片,布局很簡單,就是一個 TextVi ......

    uj5u.com 2023-04-20 08:40:31 more
  • 【FAQ】關于華為推送服務因營銷訊息頻次管控導致服務通訊類訊息

    一. 問題描述 使用華為推送服務下發IM訊息時,下發訊息請求成功且code碼為80000000,但是手機總是收不到訊息; 在華為推送自助分析(Beta)平臺查看發現,訊息發送觸發了頻控。 二. 問題原因及背景 2023年1月05日起,華為推送服務對咨詢營銷類訊息做了單個設備每日推送數量上限管理,具體 ......

    uj5u.com 2023-04-20 08:40:11 more
  • 歡迎頁輪播影片

    如圖,引導開始,球從上落下,同時淡入文字,然后文字開始輪播,最后一頁時停止,點擊進入首頁。 在來看看效果圖。 重力球先不講,主要歡迎輪播簡單實作 首先新建一個類 TextTranslationXGuideView,用于影片展示 文本是類似的,最后會有個圖片箭頭影片,布局很簡單,就是一個 TextVi ......

    uj5u.com 2023-04-20 08:39:36 more
  • 【FAQ】關于華為推送服務因營銷訊息頻次管控導致服務通訊類訊息

    一. 問題描述 使用華為推送服務下發IM訊息時,下發訊息請求成功且code碼為80000000,但是手機總是收不到訊息; 在華為推送自助分析(Beta)平臺查看發現,訊息發送觸發了頻控。 二. 問題原因及背景 2023年1月05日起,華為推送服務對咨詢營銷類訊息做了單個設備每日推送數量上限管理,具體 ......

    uj5u.com 2023-04-20 08:39:13 more
  • iOS從UI記憶體地址到讀取成員變數(oc/swift)

    開發除錯時,我們發現bug時常首先是從UI顯示發現例外,下一步才會去定位UI相關連的資料的。XCode有給我們提供一系列debug工具,但是很多人可能還沒有形成一套穩定的除錯流程,因此本文嘗試解決這個問題,順便提出一個暴論:UI顯示例外問題只需要兩個步驟就能完成定位作業的80%: 定位例外 UI 組 ......

    uj5u.com 2023-04-19 09:16:23 more
  • FIDE重磅更新!性能飛躍!體驗有禮!

    FIDE 開發者工具重構升級啦!實作500%性能提升,誠邀體驗! 一直以來不少開發者朋友在社區反饋,在使用 FIDE 工具的程序中,時常會遇到諸如加載不及時、代碼預覽/渲染性能不如意的情況,十分影響開發體驗。 作為技術團隊,我們深知一件趁手的開發工具對開發者的重要性,因此,在2023年開年,FinC ......

    uj5u.com 2023-04-19 09:16:15 more
  • 游戲內嵌社區服務開放,助力開發者提升玩家互動與留存

    華為 HMS Core 游戲內嵌社區服務提供快速訪問華為游戲中心論壇能力,支持玩家直接在游戲內瀏覽帖子和交流互動,助力開發者擴展內容生產和觸達的場景。 一、為什么要游戲內嵌社區? 二、游戲內嵌社區的典型使用場景 1、游戲內打開論壇 您可以在游戲內繪制論壇入口,為玩家提供沉浸式發帖、瀏覽、點贊、回帖、 ......

    uj5u.com 2023-04-19 09:15:46 more
  • iOS從UI記憶體地址到讀取成員變數(oc/swift)

    開發除錯時,我們發現bug時常首先是從UI顯示發現例外,下一步才會去定位UI相關連的資料的。XCode有給我們提供一系列debug工具,但是很多人可能還沒有形成一套穩定的除錯流程,因此本文嘗試解決這個問題,順便提出一個暴論:UI顯示例外問題只需要兩個步驟就能完成定位作業的80%: 定位例外 UI 組 ......

    uj5u.com 2023-04-19 09:14:53 more
  • FIDE重磅更新!性能飛躍!體驗有禮!

    FIDE 開發者工具重構升級啦!實作500%性能提升,誠邀體驗! 一直以來不少開發者朋友在社區反饋,在使用 FIDE 工具的程序中,時常會遇到諸如加載不及時、代碼預覽/渲染性能不如意的情況,十分影響開發體驗。 作為技術團隊,我們深知一件趁手的開發工具對開發者的重要性,因此,在2023年開年,FinC ......

    uj5u.com 2023-04-19 09:14:08 more
  • 游戲內嵌社區服務開放,助力開發者提升玩家互動與留存

    華為 HMS Core 游戲內嵌社區服務提供快速訪問華為游戲中心論壇能力,支持玩家直接在游戲內瀏覽帖子和交流互動,助力開發者擴展內容生產和觸達的場景。 一、為什么要游戲內嵌社區? 二、游戲內嵌社區的典型使用場景 1、游戲內打開論壇 您可以在游戲內繪制論壇入口,為玩家提供沉浸式發帖、瀏覽、點贊、回帖、 ......

    uj5u.com 2023-04-19 09:08:34 more