feat(ios): add Swift Package Manager support for iOS and macOS - #653
Closed
archie0732 wants to merge 1 commit into
Closed
feat(ios): add Swift Package Manager support for iOS and macOS#653archie0732 wants to merge 1 commit into
archie0732 wants to merge 1 commit into
Conversation
Migrates both Apple plugins to Swift Package Manager while keeping CocoaPods working: - iOS: move the Swift sources under ios/flutter_tts/Sources/flutter_tts, remove the Objective-C registration shim (FlutterTtsPlugin.h/.m) and rename SwiftFlutterTtsPlugin to FlutterTtsPlugin so the pubspec pluginClass is unchanged, matching the existing macOS implementation. - macOS: move the Swift source under macos/flutter_tts/Sources/flutter_tts. - Add ios/ and macos/ Package.swift (each depends on FlutterFramework). - Update both podspecs' source_files to the new locations and drop the obsolete iOS public_header_files entry. Verified: example builds for the iOS simulator and macOS under both Swift Package Manager and CocoaPods.
Author
|
Opened against the wrong base by mistake — this was meant for our own fork Closing; sorry for the noise. #651 is still the one worth reviewing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
移植上游 dlutton/flutter_tts#651(作者 @shivanshu877),為 iOS 與 macOS 加上 Swift Package Manager 支援。
用 cherry-pick 而不是重打一遍,所以 commit 的作者仍是原作者,內容與該 PR 一字不差(13 檔案 +62 −26)。該 PR 的 base 就是本 repo 的
master(ad4a10bb),套用時沒有任何衝突。為什麼要做
DPIP 的 iOS 端使用 Swift Package Manager,沒有 CocoaPods 的設定。
flutter_tts只提供 podspec,Flutter 每次建置都會警告:在那之前它會退回 CocoaPods,等於透過相依關係把一個 Podfile 悄悄帶回專案裡。
上游從 2026-05 起有三個功能相同的 PR(#631、#634、#651)都沒有被合併,所以在這個 fork 自行套用。
改了什麼
ios/flutter_tts/Package.swift、macos/flutter_tts/Package.swiftClasses/搬到 SPM 版面配置<platform>/flutter_tts/Sources/flutter_tts/FlutterTtsPlugin.h/.m):Swift 類別由SwiftFlutterTtsPlugin更名為FlutterTtsPlugin,可直接對應pubspec.yaml的pluginClass,不再需要轉發source_files改指新路徑;iOSdeployment_target8.0 → 12.0靜態檢查(Windows 上做得到的部分)
SwiftFlutterTtsPlugin的殘留參照pubspec.yaml的pluginClass: FlutterTtsPlugin對得上兩個平台的public class FlutterTtsPlugin,且各有一個public static func register(with:)Package.swift的 package 名稱等於目錄名、product 用短橫線、target 用底線 —— 與url_launcher_ios等官方 plugin 的慣例一致Sources/flutter_tts/底下確實有原始碼(iOS 4 個檔、macOS 1 個),podspec 的 glob 也指向該處Package.swift中的.package(name: "FlutterFramework", path: "../FlutterFramework")與awesome_notifications、awesome_notifications_fcm的寫法相同 —— DPIP 目前正在使用這兩個套件且 iOS CI 為綠,因此這個形式在專案釘選的 Flutter 3.47.0 上是可行的沒有驗證的部分
沒有 macOS 環境,因此完全沒有實際建置過。 上面全部是靜態檢查,
Package.swift沒有被任何 Swift toolchain 解析過,iOS / macOS 都沒有跑過flutter build。要合併之前,需要有 Mac 的人跑一次 example app(或直接在 DPIP 上以 git 相依指向這個分支試建)確認:
flutter build ios能通過,且不再出現 SPM 不支援的警告speak完成回呼正常想請你決定的一件事
該 commit 把
pubspec.yaml的version從4.2.5改成4.3.0,但上游尚未發布 4.3.0。若日後上游發布內容不同的 4.3.0,兩者會混淆。是否要改成
4.2.5+exptech.1之類明確標示 fork 的形式?DPIP 以 git 相依取用,版本號不影響解析,所以純粹是標示上的取捨。我沒有自行更動,因為改了這則 commit 就不再等於上游 #651,審查時無法一眼比對。另外注意(本次未動)
ios/flutter_tts.podspec的s.swift_version = '4.2'與Package.swift的swift-tools-version: 5.9不一致。這是上游原本就有的狀態,#651 沒有處理,我也刻意不動,以保持這則 commit 與原 PR 相同。要修的話建議另開一則。