教學 5 - 行動裝置:iOS

要編譯 iOS 應用程序,我們需要 Xcode,它可以從``macOS App Store <https://apps.apple.com/au/app/xcode/id497799835?mt=12>``免費獲得。

一旦我們安裝了 Xcode,我們就可以將我們的應用程式部署為 iOS 應用程式。

將應用程式部署到 iOS 的過程與部署為桌面應用程式的過程非常相似。首先,執行``create``命令 - 但這一次,我們指定要建立一個 iOS 應用程式:

(beeware-venv) $ briefcase create iOS

[helloworld] Generating application template...
Using app template: https://github.com/beeware/briefcase-iOS-Xcode-template.git, branch v0.3.18
...

[helloworld] Installing support package...
...

[helloworld] Installing application code...
Installing src/helloworld... done

[helloworld] Installing requirements...
...

[helloworld] Installing application resources...
...

[helloworld] Removing unneeded app content...
...

[helloworld] Created build/helloworld/ios/xcode

完成後,我們將擁有一個``build/helloworld/ios/xcode``目錄,其中包含 Xcode 專案以及應用程式所需的支援庫和應用程式程式碼。

然後,您可以使用``briefcase build iOS``來使用 Briefcase 來編譯您的應用程式:

(beeware-venv) $ briefcase build iOS

[helloworld] Updating app metadata...
Setting main module... done

[helloworld] Building Xcode project...
...
Building... done

[helloworld] Built build/helloworld/ios/xcode/build/Debug-iphonesimulator/Hello World.app

現在我們已經準備好使用``briefcase run iOS``來運行我們的應用程式。系統會提示您選擇要編譯的設備;如果您安裝了多個 iOS SDK 版本的模擬器,系統也可能會詢問您要定位哪個 iOS 版本。您顯示的選項可能與此輸出中顯示的選項不同 - 至少,設備清單可能會有所不同。就我們的目的而言,您選擇哪個模擬器並不重要。

(beeware-venv) $ briefcase run iOS

Select simulator device:

   1) iPad (10th generation)
   2) iPad Air (5th generation)
   3) iPad Pro (11-inch) (4th generation)
   4) iPad Pro (12.9-inch) (6th generation)
   5) iPad mini (6th generation)
   6) iPhone 14
   7) iPhone 14 Plus
   8) iPhone 14 Pro
   9) iPhone 14 Pro Max
   10) iPhone SE (3rd generation)

>  10

In the future, you could specify this device by running:

    $ briefcase run iOS -d "iPhone SE (3rd generation)::iOS 16.2"

or:

    $ briefcase run iOS -d 2614A2DD-574F-4C1F-9F1E-478F32DE282E

[helloworld] Starting app on an iPhone SE (3rd generation) running iOS 16.2 (device UDID 2614A2DD-574F-4C1F-9F1E-478F32DE282E)
Booting simulator... done
Opening simulator... done

[helloworld] Installing app...
Uninstalling any existing app version... done
Installing new app version... done

[helloworld] Starting app...
Launching app... done

[helloworld] Following simulator log output (type CTRL-C to stop log)...
===========================================================================
...

這將啟動 iOS 模擬器、安裝您的應用程式並啟動它。您應該會看到模擬器啟動,並最終打開您的 iOS 應用程式:

Hello World 教學 5 窗口,iOS 上

如果您事先知道要定位哪個 iOS 模擬器,則可以透過提供``-d``(或``–device``)選項來告訴 Briefcase 使用該模擬器。使用您在建立應用程式時選擇的設備名稱,運行:

$ briefcase run iOS -d "iPhone SE (3rd generation)"

如果您有多個可用的 iOS 版本,公事包將選擇最高的 iOS 版本;如果你想選擇一個特定的 iOS 版本,你可以告訴它使用該特定版本:

$ briefcase run iOS -d "iPhone SE (3rd generation)::iOS 15.5"

或者,您可以命名特定設備 UDID:

$ briefcase run iOS -d 2614A2DD-574F-4C1F-9F1E-478F32DE282E

下一步

現在我們的手機上已經有一個應用程式了!我們還有其他地方可以部署 BeeWare 應用程式嗎?請參閱 教學 6 以了解…