【iOS翻譯】App啟動時的響應過程

来源:https://www.cnblogs.com/xjf125/archive/2019/11/30/11961693.html
-Advertisement-
Play Games

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


 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:

  將您的應用程式的啟動時初始化代碼放在以下一個或兩個方法:

  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。

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 問題描述:今天在虛擬機下進行startup的操作,但是沒有起來,系統報錯:ORA-00845: MEMORY_TARGET not supported on this system 1.startup啟動,MEMORY_TARGET啟動不起來在系統中,Oracle總共可以使用的共用記憶體大小,這個參數 ...
  • MySQL資料庫備份和恢復 [toc] 備份恢復概述 為什麼要備份 災難恢復:硬體故障、軟體故障、自然災害、黑客攻擊、誤操作測試等數據丟失場景 備份註意要點 能容忍最多丟失多少數據 恢複數據需要在多長時間內完成 需要恢復哪些數據 還原要點 做還原測試,用於測試備份的可用性 還原演練 備份類型: 完全 ...
  • 問題描述:本來配置好的DG第二天重啟之後,發現主備庫數據不能同步,在主庫上執行日誌切換以及創建表操作都傳不到備庫上,造成這種錯誤的原因是主庫實例斷掉後造成備庫日誌與主庫無法實時接收 主庫:orcl 備庫:orclstd 說明:啟動之前主備庫都要開啟監聽,否則接收不到數據 1.在主庫上:啟動主庫,切換 ...
  • [toc] 一、準備工作 先來一段偽代碼,首先你能看懂麽? 繼續做以下的前期準備工作: 新建一個測試資料庫TestDB; 創建測試表table1和table2; 插入測試數據; 準備工作做完以後,table1和table2看起來應該像下麵這樣: 準備SQL邏輯查詢測試語句 Oracle SQL語句執 ...
  • https://www.jianshu.com/p/faa5e852b76b https://bbs.csdn.net/topics/70039385 https://www.runoob.com/sqlite/sqlite-insert.html http://c.biancheng.net/vi ...
  • 基本語法如下 sqlite> select * from tb_user; sqlite> select userid,username from tb_user; 格式化的查詢輸出 sqlite> .header on sqlite> .mode column sqlite> select * f ...
  • 概述&背景 MySQL一直被人詬病沒有實現HashJoin,最新發佈的8.0.18已經帶上了這個功能,令人欣喜。有時候在想,MySQL為什麼一直不支持HashJoin呢?我想可能是因為MySQL多用於簡單的OLTP場景,並且在互聯網應用居多,需求沒那麼緊急。另一方面可能是因為以前完全靠社區,這種演進 ...
  • SQL:Structured Quety Language SQL SERVER是一個以客戶/伺服器(c/s)模式訪問、使用Transact-SQL語言的關係型資料庫管理子系統(RDBMS) DBMS :Database Management System資料庫管理系統 資料庫:程式用來存取數據的 ...
一周排行
    -Advertisement-
    Play Games
  • Dapr Outbox 是1.12中的功能。 本文只介紹Dapr Outbox 執行流程,Dapr Outbox基本用法請閱讀官方文檔 。本文中appID=order-processor,topic=orders 本文前提知識:熟悉Dapr狀態管理、Dapr發佈訂閱和Outbox 模式。 Outbo ...
  • 引言 在前幾章我們深度講解了單元測試和集成測試的基礎知識,這一章我們來講解一下代碼覆蓋率,代碼覆蓋率是單元測試運行的度量值,覆蓋率通常以百分比表示,用於衡量代碼被測試覆蓋的程度,幫助開發人員評估測試用例的質量和代碼的健壯性。常見的覆蓋率包括語句覆蓋率(Line Coverage)、分支覆蓋率(Bra ...
  • 前言 本文介紹瞭如何使用S7.NET庫實現對西門子PLC DB塊數據的讀寫,記錄了使用電腦模擬,模擬PLC,自至完成測試的詳細流程,並重點介紹了在這個過程中的易錯點,供參考。 用到的軟體: 1.Windows環境下鏈路層網路訪問的行業標準工具(WinPcap_4_1_3.exe)下載鏈接:http ...
  • 從依賴倒置原則(Dependency Inversion Principle, DIP)到控制反轉(Inversion of Control, IoC)再到依賴註入(Dependency Injection, DI)的演進過程,我們可以理解為一種逐步抽象和解耦的設計思想。這種思想在C#等面向對象的編 ...
  • 關於Python中的私有屬性和私有方法 Python對於類的成員沒有嚴格的訪問控制限制,這與其他面相對對象語言有區別。關於私有屬性和私有方法,有如下要點: 1、通常我們約定,兩個下劃線開頭的屬性是私有的(private)。其他為公共的(public); 2、類內部可以訪問私有屬性(方法); 3、類外 ...
  • C++ 訪問說明符 訪問說明符是 C++ 中控制類成員(屬性和方法)可訪問性的關鍵字。它們用於封裝類數據並保護其免受意外修改或濫用。 三種訪問說明符: public:允許從類外部的任何地方訪問成員。 private:僅允許在類內部訪問成員。 protected:允許在類內部及其派生類中訪問成員。 示 ...
  • 寫這個隨筆說一下C++的static_cast和dynamic_cast用在子類與父類的指針轉換時的一些事宜。首先,【static_cast,dynamic_cast】【父類指針,子類指針】,兩兩一組,共有4種組合:用 static_cast 父類轉子類、用 static_cast 子類轉父類、使用 ...
  • /******************************************************************************************************** * * * 設計雙向鏈表的介面 * * * * Copyright (c) 2023-2 ...
  • 相信接觸過spring做開發的小伙伴們一定使用過@ComponentScan註解 @ComponentScan("com.wangm.lifecycle") public class AppConfig { } @ComponentScan指定basePackage,將包下的類按照一定規則註冊成Be ...
  • 操作系統 :CentOS 7.6_x64 opensips版本: 2.4.9 python版本:2.7.5 python作為腳本語言,使用起來很方便,查了下opensips的文檔,支持使用python腳本寫邏輯代碼。今天整理下CentOS7環境下opensips2.4.9的python模塊筆記及使用 ...