Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,11 @@ example/lib/firebase_options.dart
example/macos/Runner/GoogleService-Info.plist

example/firebase.json

# Swift Package Manager (plugin packages only - an app's Package.resolved should be committed)
ios/twilio_voice/.build/
ios/twilio_voice/.swiftpm/
ios/twilio_voice/Package.resolved
macos/twilio_voice/.build/
macos/twilio_voice/.swiftpm/
macos/twilio_voice/Package.resolved
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Next Release

* feat: [iOS, macOS] Swift Package Manager support added, enable it with `flutter config --enable-swift-package-manager`. _Note: projects using CocoaPods will continue to use CocoaPods, and SPM is only used for new projects or those that have opted in._
* feat: added call quality events for all platforms (see `CallQualityEvent` and `TwilioVoicePlatform.instance.call.qualityWarnings`, and [Twilio Call Quality Metrics](https://www.twilio.com/docs/voice/voice-insights/api/call/details-sdk-call-quality-events#error-and-warning-events))
* Updated Example
* Updated docs
Expand Down
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,36 @@ Please follow Twilio's quickstart setup for each platform, you don't need to wri
but it will help you understand the basic functionality of setting up your server, registering your
iOS app for VOIP, etc.

### Swift Package Manager (iOS & macOS)

This plugin ships both a Swift package and a podspec, so it works with either integration. If your
app uses CocoaPods there is nothing to do - it keeps working exactly as before.

To use Swift Package Manager instead, enable it once for your Flutter install:

```bash
flutter config --enable-swift-package-manager
```

Flutter then resolves this plugin through SPM, and the iOS Twilio Voice SDK is pulled from
[twilio/twilio-voice-ios](https://github.com/twilio/twilio-voice-ios) (6.13.6+) instead of the
`TwilioVoice` pod. `TwilioVoice.framework` is embedded into your app automatically; no manual
"Frameworks, Libraries and Embedded Content" step is needed.

Two things to be aware of:

- **macOS apps must set their deployment target to 11.0 or later.** CocoaPods tolerates an app
target below a pod's minimum, but SwiftPM does not, and the build fails with:

> error: The package product 'twilio-voice' requires minimum platform version 11.0 for the macOS
> platform, but this target supports 10.15

Set `macOS Deployment Target` to `11.0` on the Runner target in Xcode (Flutter's own template
still defaults to 10.15). iOS already requires 13.0, which matches Flutter's template default.

- Enabling SPM is a per-machine Flutter setting, not a per-project one. Plugins that do not yet
support SPM continue to be resolved through CocoaPods alongside it, so mixed projects are fine.

### iOS Setup

To customize the icon displayed on a CallKit call, Open XCode and add a png icon named '
Expand Down
4 changes: 0 additions & 4 deletions ios/Classes/TwilioVoicePlugin.h

This file was deleted.

15 changes: 0 additions & 15 deletions ios/Classes/TwilioVoicePlugin.m

This file was deleted.

2 changes: 1 addition & 1 deletion ios/twilio_voice.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Pod::Spec.new do |s|
s.license = { :file => '../LICENSE' }
s.author = { 'Charles Dyason' => 'charles@earthbase.io' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.source_files = 'twilio_voice/Sources/twilio_voice/**/*.swift'
s.dependency 'Flutter'
s.dependency 'TwilioVoice','~> 6.13.6'
s.platform = :ios, '13.0'
Expand Down
29 changes: 29 additions & 0 deletions ios/twilio_voice/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "twilio_voice",
platforms: [
.iOS("13.0")
],
products: [
.library(name: "twilio-voice", targets: ["twilio_voice"])
],
dependencies: [
// Mirrors the `TwilioVoice` CocoaPods dependency in `ios/twilio_voice.podspec`. Keep the two
// version constraints in step so an app gets the same SDK whichever integration it uses.
.package(url: "https://github.com/twilio/twilio-voice-ios", from: "6.13.6")
],
targets: [
.target(
name: "twilio_voice",
dependencies: [
// The dynamic variant, matching what the CocoaPods integration vendors. Twilio also
// publishes `TwilioVoice-static`, which additionally requires SystemConfiguration.
.product(name: "TwilioVoice", package: "twilio-voice-ios")
]
)
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import TwilioVoice
import CallKit
import UserNotifications

/// Exposed to Objective-C as `TwilioVoicePlugin`, which is the class name Flutter's generated
/// plugin registrant calls into (`pluginClass` in `pubspec.yaml`).
///
/// This used to be a separate Objective-C shim (`TwilioVoicePlugin.h/.m`) that forwarded to this
/// class. Swift Package Manager does not support mixed-language targets, so the shim was removed
/// and its Objective-C name adopted here instead - keeping the registrant, and any manual
/// `[TwilioVoicePlugin registerWithRegistrar:]` call, working unchanged.
@objc(TwilioVoicePlugin)
public class SwiftTwilioVoicePlugin: NSObject, FlutterPlugin, FlutterStreamHandler, PKPushRegistryDelegate, NotificationDelegate, CallDelegate, AVAudioPlayerDelegate, CXProviderDelegate {
let callObserver = CXCallObserver()

Expand Down
4 changes: 2 additions & 2 deletions macos/twilio_voice.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ A new Flutter plugin project.
s.author = { 'Your Company' => 'email@example.com' }

s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.source_files = 'twilio_voice/Sources/twilio_voice/**/*.swift'
s.dependency 'FlutterMacOS'

s.platform = :osx, '11.0'
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
s.swift_version = '5.0'
s.resources = "Resources/*"
s.resources = 'twilio_voice/Sources/twilio_voice/Resources/*'
end
26 changes: 26 additions & 0 deletions macos/twilio_voice/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "twilio_voice",
platforms: [
.macOS("11.0")
],
products: [
.library(name: "twilio-voice", targets: ["twilio_voice"])
],
dependencies: [],
targets: [
.target(
name: "twilio_voice",
dependencies: [],
resources: [
// `index.html` is the page hosted by the plugin's WKWebView. `.process` flattens it into
// the generated resource bundle, so it is looked up via `Bundle.module` - see TVWebView.
.process("Resources")
]
)
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public class TVWebView: WKWebView, WKUIDelegate {
overrideLogging()
injectTwilioVoiceSDK()

let bundle = Bundle(for: TwilioVoicePlugin.self)
if let url = bundle.url(forResource: "Resources/index", withExtension: "html") {
if let url = TVWebView.indexPageURL() {
loadFileURL(url, allowingReadAccessTo: url.deletingLastPathComponent())
} else {
NSLog("""
Expand All @@ -28,6 +27,20 @@ public class TVWebView: WKWebView, WKUIDelegate {
}
}

/// Locates `index.html`, the page this webview hosts.
///
/// Where it lives depends on how the plugin was integrated. Under Swift Package Manager the
/// file is declared as a package resource and lands in the package's generated resource
/// bundle, reachable only through `Bundle.module`. Under CocoaPods it is copied into the
/// plugin framework's own `Resources` directory instead.
private static func indexPageURL() -> URL? {
#if SWIFT_PACKAGE
return Bundle.module.url(forResource: "index", withExtension: "html")
#else
return Bundle(for: TwilioVoicePlugin.self).url(forResource: "Resources/index", withExtension: "html")
#endif
}

/// Asset path of the bundled Twilio Voice JS SDK, as declared in the plugin's `pubspec.yaml`.
private static let sdkAsset = "assets/twilio.min.js"
private static let sdkPackage = "twilio_voice"
Expand Down
Loading