From a532029b46fccf0d5e40be0223496389077e5be4 Mon Sep 17 00:00:00 2001 From: Jaesung Date: Mon, 28 Sep 2020 11:09:13 +0900 Subject: [PATCH 1/8] Modify to allow only 1 ongoing call --- QuickStart/AppDelegate+VoIPPush.swift | 15 ++++++++++++++- .../CXExtensions/CXProvider+QuickStart.swift | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/QuickStart/AppDelegate+VoIPPush.swift b/QuickStart/AppDelegate+VoIPPush.swift index 35f85ae3..8d93f9ed 100644 --- a/QuickStart/AppDelegate+VoIPPush.swift +++ b/QuickStart/AppDelegate+VoIPPush.swift @@ -38,7 +38,7 @@ extension AppDelegate: PKPushRegistryDelegate { // Please refer to `AppDelegate+SendBirdCallsDelegates.swift` file. func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) { SendBirdCall.pushRegistry(registry, didReceiveIncomingPushWith: payload, for: type) { uuid in - guard uuid != nil else { + guard let uuid = uuid, let call = SendBirdCall.getCall(forUUID: uuid) else { let update = CXCallUpdate() update.remoteHandle = CXHandle(type: .generic, value: "invalid") let randomUUID = UUID() @@ -50,6 +50,19 @@ extension AppDelegate: PKPushRegistryDelegate { return } + if SendBirdCall.getOngoingCallCount() > 1 { + let update = CXCallUpdate() + update.remoteHandle = CXHandle(type: .generic, value: call.remoteUser?.userId ?? "invalid") + update.hasVideo = call.isVideoCall + + CXCallManager.shared.reportIncomingCall(with: uuid, update: update) { _ in + CXCallManager.shared.endCall(for: uuid, endedAt: Date(), reason: .declined) + } + + call.end() + return + } + completion() } } diff --git a/QuickStart/CXExtensions/CXProvider+QuickStart.swift b/QuickStart/CXExtensions/CXProvider+QuickStart.swift index 796793f2..cd1f6dca 100644 --- a/QuickStart/CXExtensions/CXProvider+QuickStart.swift +++ b/QuickStart/CXExtensions/CXProvider+QuickStart.swift @@ -20,6 +20,7 @@ extension CXProviderConfiguration { // and update correct type of call log in Recents providerConfiguration.supportsVideo = true providerConfiguration.maximumCallsPerCallGroup = 1 + providerConfiguration.maximumCallGroups = 1 providerConfiguration.supportedHandleTypes = [.generic] // Set up ringing sound From 06044748d4ae7facdaeec3b822146582e6a5a8c2 Mon Sep 17 00:00:00 2001 From: Jaesung Date: Mon, 28 Sep 2020 13:13:41 +0900 Subject: [PATCH 2/8] Move logic to `didStartRinging(call:)` --- .../AppDelegate+SendBirdCallsDelegates.swift | 12 ++++++++++-- QuickStart/AppDelegate+VoIPPush.swift | 15 +-------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/QuickStart/AppDelegate+SendBirdCallsDelegates.swift b/QuickStart/AppDelegate+SendBirdCallsDelegates.swift index 0c7195fb..99ecec72 100644 --- a/QuickStart/AppDelegate+SendBirdCallsDelegates.swift +++ b/QuickStart/AppDelegate+SendBirdCallsDelegates.swift @@ -27,8 +27,16 @@ extension AppDelegate: SendBirdCallDelegate, DirectCallDelegate { update.hasVideo = call.isVideoCall update.localizedCallerName = call.caller?.userId ?? "Unknown" - // Report the incoming call to the system - CXCallManager.shared.reportIncomingCall(with: uuid, update: update) + if SendBirdCall.getOngoingCallCount() > 1 { + // Allow only one ongoing call. + CXCallManager.shared.reportIncomingCall(with: uuid, update: update) { _ in + CXCallManager.shared.endCall(for: uuid, endedAt: Date(), reason: .declined) + } + call.end() + } else { + // Report the incoming call to the system + CXCallManager.shared.reportIncomingCall(with: uuid, update: update) + } } // MARK: DirectCallDelegate diff --git a/QuickStart/AppDelegate+VoIPPush.swift b/QuickStart/AppDelegate+VoIPPush.swift index 8d93f9ed..35f85ae3 100644 --- a/QuickStart/AppDelegate+VoIPPush.swift +++ b/QuickStart/AppDelegate+VoIPPush.swift @@ -38,7 +38,7 @@ extension AppDelegate: PKPushRegistryDelegate { // Please refer to `AppDelegate+SendBirdCallsDelegates.swift` file. func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) { SendBirdCall.pushRegistry(registry, didReceiveIncomingPushWith: payload, for: type) { uuid in - guard let uuid = uuid, let call = SendBirdCall.getCall(forUUID: uuid) else { + guard uuid != nil else { let update = CXCallUpdate() update.remoteHandle = CXHandle(type: .generic, value: "invalid") let randomUUID = UUID() @@ -50,19 +50,6 @@ extension AppDelegate: PKPushRegistryDelegate { return } - if SendBirdCall.getOngoingCallCount() > 1 { - let update = CXCallUpdate() - update.remoteHandle = CXHandle(type: .generic, value: call.remoteUser?.userId ?? "invalid") - update.hasVideo = call.isVideoCall - - CXCallManager.shared.reportIncomingCall(with: uuid, update: update) { _ in - CXCallManager.shared.endCall(for: uuid, endedAt: Date(), reason: .declined) - } - - call.end() - return - } - completion() } } From dc340a0a560b06fed6a44408987f7d01f9488d5d Mon Sep 17 00:00:00 2001 From: Jaesung Date: Wed, 4 Nov 2020 10:56:30 +0900 Subject: [PATCH 3/8] Add background task for declining --- QuickStart/CXExtensions/CXCallManager.swift | 38 +++++++++++++++------ 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/QuickStart/CXExtensions/CXCallManager.swift b/QuickStart/CXExtensions/CXCallManager.swift index 21a9975d..1838205e 100644 --- a/QuickStart/CXExtensions/CXCallManager.swift +++ b/QuickStart/CXExtensions/CXCallManager.swift @@ -134,18 +134,36 @@ extension CXCallManager: CXProviderDelegate { return } - // For decline - if call.endResult == DirectCallEndResult.none || call.endResult == .unknown { - SendBirdCall.authenticateIfNeed { [weak call] (error) in - guard let call = call, error == nil else { - action.fail() - return + var backgroundTaskID: UIBackgroundTaskIdentifier = .invalid + + // For decline in background + DispatchQueue.global().async { + backgroundTaskID = UIApplication.shared.beginBackgroundTask { + UIApplication.shared.endBackgroundTask(backgroundTaskID) + backgroundTaskID = .invalid + } + + if call.endResult == DirectCallEndResult.none || call.endResult == .unknown { + SendBirdCall.authenticateIfNeed { [weak call] (error) in + guard let call = call, error == nil else { + action.fail() + return + } + + call.end { + action.fulfill() + + // End background task + UIApplication.shared.endBackgroundTask(backgroundTaskID) + backgroundTaskID = .invalid + } } - - call.end { action.fulfill() } + } else { + action.fulfill() } - } else { - action.fulfill() + + + } } From d9c4d940ddfe80be4039300973131a0168678053 Mon Sep 17 00:00:00 2001 From: Jaesung Date: Wed, 4 Nov 2020 11:07:42 +0900 Subject: [PATCH 4/8] Fix error on configure app ID --- QuickStart/AppDelegate.swift | 5 +++-- QuickStart/Extensions/UserDefaults+QuickStart.swift | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/QuickStart/AppDelegate.swift b/QuickStart/AppDelegate.swift index b8b1bc4f..77189665 100644 --- a/QuickStart/AppDelegate.swift +++ b/QuickStart/AppDelegate.swift @@ -25,6 +25,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // MARK: SendBirdCall.configure(appId:) // See [here](https://github.com/sendbird/quickstart-calls-ios#creating-a-sendbird-application) for the application ID. + // If you want to sign in with QR code, don't configure your app ID in code. // SendBirdCall.configure(appId: YOUR_APP_ID) self.autoSignIn { error in @@ -80,8 +81,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } func authenticate(with credential: Credential, completionHandler: @escaping (Error?) -> Void) { - // Configure app ID before authenticate - SendBirdCall.configure(appId: credential.appId) + // Configure app ID before authenticate when there is no configured app ID + if SendBirdCall.appId == nil { SendBirdCall.configure(appId: credential.appId) } // Authenticate let authParams = AuthenticateParams(userId: credential.userId, accessToken: credential.accessToken) diff --git a/QuickStart/Extensions/UserDefaults+QuickStart.swift b/QuickStart/Extensions/UserDefaults+QuickStart.swift index bee7f1b5..2f1b52b9 100644 --- a/QuickStart/Extensions/UserDefaults+QuickStart.swift +++ b/QuickStart/Extensions/UserDefaults+QuickStart.swift @@ -39,8 +39,10 @@ extension UserDefaults { extension UserDefaults { func clear() { - let keys = Key.allCases.filter { $0 != .voipPushToken } - keys.map { $0.value }.forEach(UserDefaults.standard.removeObject) + Key.allCases + .filter { $0 != .voipPushToken } + .map { $0.value } + .forEach(UserDefaults.standard.removeObject) } } From 406ae2a5351823961f57491971c07ad9406a5ac5 Mon Sep 17 00:00:00 2001 From: Jaesung Date: Wed, 4 Nov 2020 11:22:30 +0900 Subject: [PATCH 5/8] Remove vertical spaces --- QuickStart/CXExtensions/CXCallManager.swift | 3 --- 1 file changed, 3 deletions(-) diff --git a/QuickStart/CXExtensions/CXCallManager.swift b/QuickStart/CXExtensions/CXCallManager.swift index 1838205e..711c47e3 100644 --- a/QuickStart/CXExtensions/CXCallManager.swift +++ b/QuickStart/CXExtensions/CXCallManager.swift @@ -161,9 +161,6 @@ extension CXCallManager: CXProviderDelegate { } else { action.fulfill() } - - - } } From 46982a51bbf6fc1a7b668bb98ea95db6d26f88e0 Mon Sep 17 00:00:00 2001 From: Jaesung Date: Mon, 9 Nov 2020 10:22:42 +0900 Subject: [PATCH 6/8] Fix bug on end result message in Recents view --- QuickStart/CallHistory/CallHistory.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QuickStart/CallHistory/CallHistory.swift b/QuickStart/CallHistory/CallHistory.swift index 2dc1809a..f49501ff 100644 --- a/QuickStart/CallHistory/CallHistory.swift +++ b/QuickStart/CallHistory/CallHistory.swift @@ -39,7 +39,7 @@ struct CallHistory: Codable { self.startedAt = CallHistory.dateFormatter.string(from: Date(timeIntervalSince1970: Double(callLog.startedAt) / 1000)) self.duration = callLog.duration.durationText() - self.endResult = callLog.endResult.rawValue + self.endResult = CallStatus.ended(result: callLog.endResult.rawValue).message } } From b64856bf5ada409969679138157f48065f8bbd3c Mon Sep 17 00:00:00 2001 From: Jaesung Date: Mon, 9 Nov 2020 11:43:37 +0900 Subject: [PATCH 7/8] Capitalize first letter of end result --- QuickStart/Dial/CallStatus.swift | 11 ++++++++--- QuickStart/Extensions/String+QuickStart.swift | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/QuickStart/Dial/CallStatus.swift b/QuickStart/Dial/CallStatus.swift index 41cbeb80..734768e6 100644 --- a/QuickStart/Dial/CallStatus.swift +++ b/QuickStart/Dial/CallStatus.swift @@ -13,9 +13,14 @@ enum CallStatus { var message: String { switch self { - case .connecting: return "call connecting..." - case .muted(let user): return "\(user) is muted" - case .ended(let result): return result.replacingOccurrences(of: "_", with: " ") + case .connecting: + return "call connecting..." + case .muted(let user): + return "\(user) is muted" + case .ended(let result): + return result + .replacingOccurrences(of: "_", with: " ") + .capitalizingFirstLetter() } } } diff --git a/QuickStart/Extensions/String+QuickStart.swift b/QuickStart/Extensions/String+QuickStart.swift index 4e61ebfb..7c9803f8 100644 --- a/QuickStart/Extensions/String+QuickStart.swift +++ b/QuickStart/Extensions/String+QuickStart.swift @@ -23,6 +23,10 @@ extension String { return self.trimmed } } + + public func capitalizingFirstLetter() -> String { + return prefix(1).capitalized + dropFirst() + } } extension Optional where Wrapped == String { From 39cf0993e794e79ce6b1bb29e5fb3aeb5cd358c7 Mon Sep 17 00:00:00 2001 From: Jaesung Date: Mon, 9 Nov 2020 15:09:45 +0900 Subject: [PATCH 8/8] Bump up version --- QuickStart.xcodeproj/project.pbxproj | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/QuickStart.xcodeproj/project.pbxproj b/QuickStart.xcodeproj/project.pbxproj index e31ac964..d87a029d 100644 --- a/QuickStart.xcodeproj/project.pbxproj +++ b/QuickStart.xcodeproj/project.pbxproj @@ -879,7 +879,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = QuickStart/QuickStart.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = RM4A5PXTUX; EXCLUDED_ARCHS = ""; FRAMEWORK_SEARCH_PATHS = ( @@ -892,7 +892,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.3.0; + MARKETING_VERSION = 1.4.0; PRODUCT_BUNDLE_IDENTIFIER = com.sendbird.calls.quickstart; PRODUCT_NAME = "Sendbird Calls"; SWIFT_VERSION = 5.0; @@ -909,7 +909,7 @@ CODE_SIGN_ENTITLEMENTS = QuickStart/QuickStart.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = RM4A5PXTUX; EXCLUDED_ARCHS = ""; FRAMEWORK_SEARCH_PATHS = ( @@ -922,7 +922,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.3.0; + MARKETING_VERSION = 1.4.0; PRODUCT_BUNDLE_IDENTIFIER = com.sendbird.calls.quickstart; PRODUCT_NAME = "Sendbird Calls"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -944,7 +944,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.3.0; + MARKETING_VERSION = 1.4.0; PRODUCT_BUNDLE_IDENTIFIER = com.sendbird.calls.quickstart.QuickStartIntent; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -967,7 +967,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.3.0; + MARKETING_VERSION = 1.4.0; PRODUCT_BUNDLE_IDENTIFIER = com.sendbird.calls.quickstart.QuickStartIntent; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES;