Skip to content

Commit 8fa0460

Browse files
author
Jaesung
authored
Merge pull request #43 from sendbird/feature/jaesung/app-terminate
End ongoing calls when application will terminate
2 parents fcb70ec + cafb5c6 commit 8fa0460

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

QuickStart/AppDelegate.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,29 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
4141

4242
return true
4343
}
44+
45+
func applicationWillTerminate(_ application: UIApplication) {
46+
// This method will be called when the app is forcefully terminated.
47+
// End all ongoing calls in this method.
48+
let callManager = CXCallManager.shared
49+
let ongoingCalls = callManager.currentCalls.compactMap { SendBirdCall.getCall(forUUID: $0.uuid) }
50+
51+
ongoingCalls.forEach { directCall in
52+
// Sendbird Calls: End call
53+
directCall.end()
54+
55+
// CallKit: Request End transaction
56+
callManager.endCXCall(directCall)
57+
58+
// CallKit: Report End if uuid is valid
59+
if let uuid = directCall.callUUID {
60+
callManager.endCall(for: uuid, endedAt: Date(), reason: .none)
61+
}
62+
}
63+
// However, because iOS gives a limited time to perform remaining tasks,
64+
// There might be some calls failed to be ended
65+
// In this case, I recommend that you register local notification to notify the unterminated calls.
66+
}
4467
}
4568

4669
extension AppDelegate: PKPushRegistryDelegate {

0 commit comments

Comments
 (0)