-
Notifications
You must be signed in to change notification settings - Fork 7
CallKit minimal demo #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
88be436
Call kit minimal demo
hiroshihorie a826af7
PushKit
hiroshihorie 6f19978
Updates
hiroshihorie 41b54b5
Use branch temporarily
hiroshihorie dbe26ee
Readme
hiroshihorie 4577b6e
readme md
hiroshihorie 7181bd2
Fixes
hiroshihorie ca512f9
Simplify init
hiroshihorie c2dd922
AppUsesNonExemptEncryption
hiroshihorie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| *.png filter=lfs diff=lfs merge=lfs -text |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # Xcode | ||
| # | ||
| # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore | ||
|
|
||
| ## User settings | ||
| xcuserdata/ | ||
|
|
||
| ## Obj-C/Swift specific | ||
| *.hmap | ||
|
|
||
| ## App packaging | ||
| *.ipa | ||
| *.dSYM.zip | ||
| *.dSYM | ||
|
|
||
| ## Playgrounds | ||
| timeline.xctimeline | ||
| playground.xcworkspace | ||
|
|
||
| # Swift Package Manager | ||
| # | ||
| # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. | ||
| # Packages/ | ||
| # Package.pins | ||
| # Package.resolved | ||
| # *.xcodeproj | ||
| # | ||
| # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata | ||
| # hence it is not needed unless you have added a package configuration file to your project | ||
| # .swiftpm | ||
|
|
||
| .build/ | ||
|
|
||
| # CocoaPods | ||
| # | ||
| # We recommend against adding the Pods directory to your .gitignore. However | ||
| # you should judge for yourself, the pros and cons are mentioned at: | ||
| # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control | ||
| # | ||
| # Pods/ | ||
| # | ||
| # Add this line if you want to avoid checking in source code from the Xcode workspace | ||
| # *.xcworkspace | ||
|
|
||
| # Carthage | ||
| # | ||
| # Add this line if you want to avoid checking in source code from Carthage dependencies. | ||
| # Carthage/Checkouts | ||
|
|
||
| Carthage/Build/ | ||
|
|
||
| # fastlane | ||
| # | ||
| # It is recommended to not store the screenshots in the git repo. | ||
| # Instead, use fastlane to re-generate the screenshots whenever they are needed. | ||
| # For more information about the recommended setup visit: | ||
| # https://docs.fastlane.tools/best-practices/source-control/#source-control | ||
|
|
||
| fastlane/report.xml | ||
| fastlane/Preview.html | ||
| fastlane/screenshots/**/*.png | ||
| fastlane/test_output |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 5.9 |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --exclude Sources/LiveKit/Protos | ||
| --header "/*\n * Copyright {year} LiveKit\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */" | ||
| --ifdef no-indent | ||
| --disable modifiersOnSameLine |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # CallKit + PushKit example | ||
|
|
||
| This example demonstrates how to use the LiveKit Swift SDK with CallKit and PushKit. | ||
|
|
||
| ### Testing remote VoIP pushes | ||
|
|
||
| Use the [Push Notification Console](https://developer.apple.com/documentation/usernotifications/testing-notifications-using-the-push-notification-console) to send a `VoIP` push to your token. | ||
|
|
||
| You can obtain the push token by running the example app on a device. | ||
|
|
||
| ### Key points when integrating LiveKit SDK with CallKit | ||
|
|
||
| CallKit on iOS sets AVAudioSession active automatically at specific timings. | ||
| By default, the LiveKit Swift SDK also configures the AVAudioSession automatically, which will interfere with CallKit. | ||
|
|
||
| We should ensure proper timing when configuring `AVAudioSession` and starting the SDK's internal `AVAudioEngine` between | ||
| [provider(_:didActivate:)](https://developer.apple.com/documentation/callkit/cxproviderdelegate/provider(_:didactivate:)) and [provider(_:didDeactivate:)](https://developer.apple.com/documentation/callkit/cxproviderdelegate/provider(_:diddeactivate:)). | ||
|
|
||
| Early in the process, we should disable automatic AVAudioSession configuration: | ||
| ```swift | ||
| AudioManager.shared.audioSession.isAutomaticConfigurationEnabled = false | ||
| ``` | ||
|
|
||
| We should also ensure the SDK's internal `AVAudioEngine` will not start, even when subscribing to remote audio or publishing microphone: | ||
| ```swift | ||
| try AudioManager.shared.setEngineAvailability(.none) | ||
| ``` | ||
|
|
||
| Now, in the `CXProviderDelegate`, we want to ensure `AVAudioSession.category` is set to `.playAndRecord` (if you will publish microphone). | ||
| We also want to allow the SDK's internal `AVAudioEngine` to start within the `didActivate` ~ `didDeactivate` window. | ||
| ```swift | ||
| func provider(_: CXProvider, didActivate session: AVAudioSession) { | ||
| do { | ||
| try session.setCategory(.playAndRecord, mode: .voiceChat, options: [.mixWithOthers]) | ||
| try AudioManager.shared.setEngineAvailability(.default) | ||
| } catch { | ||
| // Error | ||
| } | ||
| } | ||
|
|
||
| func provider(_: CXProvider, didDeactivate _: AVAudioSession) { | ||
| do { | ||
| try AudioManager.shared.setEngineAvailability(.none) | ||
| } catch { | ||
| // Error | ||
| } | ||
| } | ||
| ``` | ||
| > **NOTE:** We don't call `session.setActive(true)` since CallKit already activates it and Apple doesn't recommend calling it again. | ||
|
|
||
| With this setup, you can connect, publish, and subscribe to audio at timings convenient to your implementation and requirements. See the source code of this example for details. | ||
|
|
||
| ### CallKit lock screen / background issues | ||
|
|
||
| These are issues I've encountered while implementing this example. Please let me know if there are better workarounds or if I'm incorrect. | ||
|
|
||
| 1. [reportNewIncomingCall(with:update:completion:)](https://developer.apple.com/documentation/callkit/cxprovider/reportnewincomingcall(with:update:completion:)) must be invoked on the same thread as [pushRegistry(_:didReceiveIncomingPushWith:for:completion:)](https://developer.apple.com/documentation/pushkit/pkpushregistrydelegate/pushregistry(_:didreceiveincomingpushwith:for:completion:)), otherwise it will silently fail and not show the incoming call UI on the lock screen. Therefore, the async version may not work as intended. | ||
|
|
||
| 2. You may need to set `AVAudioSession.category` to `.playAndRecord` before calling [reportNewIncomingCall(with:update:completion:)](https://developer.apple.com/documentation/callkit/cxprovider/reportnewincomingcall(with:update:completion:)) when your app is woken up in the background by [pushRegistry(_:didReceiveIncomingPushWith:for:completion:)](https://developer.apple.com/documentation/pushkit/pkpushregistrydelegate/pushregistry(_:didreceiveincomingpushwith:for:completion:)). | ||
|
|
||
| ### References | ||
|
|
||
| [Responding to VoIP Notifications from PushKit](https://developer.apple.com/documentation/pushkit/responding-to-voip-notifications-from-pushkit) | ||
| [Developer Forums: CallKit does not activate audio session](https://developer.apple.com/forums/thread/783870) | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
87 changes: 87 additions & 0 deletions
87
callkit/callkit-dev.xcworkspace/xcshareddata/swiftpm/Package.resolved
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just become the delegate and do it under the hood?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, we could, but I’m starting to think that configuring AVAudioSession on the user’s behalf is not a good idea in the long run.