官方文檔
官方中文文檔鏈接:https://flutter.cn/docs/deployment/ios
官方文檔中步驟描述并不清晰,同時在操作過程中會遇到一些bug,在這里記錄一下。
操作流程
預先準備
應用圖標
IOS要求應用圖標為一個1024*1024像素大小的PNG圖片,不能包含Alpha通道和透明度。
準備好圖標圖片后,放在項目assets任意位置,然后使用 flutter_launcher_icons 包來自動生成項目中需要的圖標,它會同時生成Android和IOS需要的圖標文件。
在pubspec.yaml中配置依賴包,和原始圖標路徑:
dev_dependencies:
flutter_launcher_icons: "^0.7.3"
flutter_icons:
android: "launcher_icon"
ios: true
image_path: "assets/icon/icon.png"
安裝依賴并運行命令生成圖標:
flutter pub get
flutter pub run flutter_launcher_icons:main
開發(fā)者賬號注冊
需要注冊 Apple Developer Program,選擇任意類型的開發(fā)者,最低標準的個人開發(fā)者需要¥688每年。
可以通過 App Store Connect App注冊,該App中可以直接購買開發(fā)者計劃并付費。
注冊App
根據(jù)官方文檔,首先要登記套裝 ID,該ID應該在真機測試的階段在Xcode中就配置好了,所以此處略過。
然后登陸網(wǎng)頁版的 App Store Connect ,新建App,并填寫基本信息。
檢查 Xcode 項目設(shè)置
根據(jù)官方文檔中的檢查列表檢查設(shè)置,但是注意:
- Runner > General > Identity > Display Name 內(nèi)容不能修改,需要保持為
Runner。如果修改了會導致運行flutter build ios找不到runner報錯。修改app名稱應該在Info.plist中修改CFBundleName。 - Runner > General > Frameworks 中App.framework、Flutter.framework和Pods_Runner.framework的Embed狀態(tài)都應該為Embed & Sign。
創(chuàng)建一個構(gòu)建歸檔(build archive)
根據(jù)官方文檔操作,另外還需注意:
- 我當前使用的
Flutter 1.12.13+IOS 13.3.1+Xcode 11在進行 Product > Archive 創(chuàng)建歸檔的時候報錯,此時需要將Pods_Runner.framework的狀態(tài)修改為Do Not Embed,然后進行歸檔(當然在flutter build ios的時候還要改回Embed & Sign)。 - 項目中使用了 flutter_local_notifications 包來進行本地通知推送,而該包依賴另一個 permission_handler 包來進行權(quán)限獲取,它默認是獲取全部權(quán)限的,而有些權(quán)限在項目中并沒有用到,所以還需要根據(jù)其文檔在
Podfile中進行權(quán)限配置。確實用的的權(quán)限需要在`Info.plist中添加對應的權(quán)限使用說明。 - IOS要求添加
Push Notifications的權(quán)限配置,即使項目僅使用了Local Notification,在 Runner > Signing & Capabilities 中點擊+ Capability并添加Push Notifications,這樣在build的時候Xcode就會生成entitlement file。如果沒有自動生成的話,可以手動添加到Runner目錄中,文件名為Runner.entitlement:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>aps-environment</key>
<string>development</string>
</dict>
</plist>
發(fā)布到TestFlight
發(fā)布成功,邀請內(nèi)部測試人員測試。