Skip to content

Commit 45548e2

Browse files
author
Jaesung
authored
Merge pull request #20 from sendbird/feature/jaesung/fix-receiving-pushtoken
Fix push notification error after first signing in
2 parents 9b547fa + 2bc5de1 commit 45548e2

File tree

11 files changed

+59
-20
lines changed

11 files changed

+59
-20
lines changed

QuickStart.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@
533533
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
534534
CODE_SIGN_ENTITLEMENTS = QuickStart/QuickStart.entitlements;
535535
CODE_SIGN_STYLE = Automatic;
536-
CURRENT_PROJECT_VERSION = 12;
536+
CURRENT_PROJECT_VERSION = 17;
537537
DEVELOPMENT_TEAM = RM4A5PXTUX;
538538
FRAMEWORK_SEARCH_PATHS = (
539539
"$(inherited)",
@@ -561,7 +561,7 @@
561561
CODE_SIGN_ENTITLEMENTS = QuickStart/QuickStart.entitlements;
562562
CODE_SIGN_IDENTITY = "Apple Development";
563563
CODE_SIGN_STYLE = Automatic;
564-
CURRENT_PROJECT_VERSION = 12;
564+
CURRENT_PROJECT_VERSION = 17;
565565
DEVELOPMENT_TEAM = RM4A5PXTUX;
566566
FRAMEWORK_SEARCH_PATHS = (
567567
"$(inherited)",

QuickStart/AppDelegate.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
4141
// QR Code Mode
4242
SendBirdCall.configure(appId: appId)
4343
}
44-
45-
SendBirdCall.addDelegate(self, identifier: "DelegateIdentification")
44+
45+
// You must call `SendBirdCall.addDelegate(_:identifier:)` right after configuring new app ID
46+
SendBirdCall.addDelegate(self, identifier: "com.sendbird.calls.quickstart.delegate")
4647

4748
self.voipRegistration()
4849

@@ -63,13 +64,13 @@ extension AppDelegate: PKPushRegistryDelegate {
6364

6465
// MARK: SendBirdCalls - Registering push token.
6566
func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
67+
UserDefaults.standard.voipPushToken = pushCredentials.token
68+
print("Push token is \(pushCredentials.token.toHexString())")
69+
6670
SendBirdCall.registerVoIPPush(token: pushCredentials.token, unique: true) { error in
6771
guard error == nil else { return }
6872
// Even if an error occurs, SendBirdCalls will save the pushToken value and reinvoke this method internally while authenticating.
6973
}
70-
UserDefaults.standard.pushToken = pushCredentials.token
71-
72-
print("Push token is \(pushCredentials.token.toHexString())")
7374
}
7475

7576
// MARK: SendBirdCalls - Receive incoming push event
@@ -81,6 +82,17 @@ extension AppDelegate: PKPushRegistryDelegate {
8182
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
8283
// MARK: Handling incoming call
8384
SendBirdCall.pushRegistry(registry, didReceiveIncomingPushWith: payload, for: type) { uuid in
85+
guard uuid != nil else {
86+
let update = CXCallUpdate()
87+
update.remoteHandle = CXHandle(type: .generic, value: "invalid")
88+
let randomUUID = UUID()
89+
self.provider.reportNewIncomingCall(with: randomUUID, update: update) { error in
90+
self.provider.reportCall(with: randomUUID, endedAt: Date(), reason: .failed)
91+
}
92+
completion()
93+
return
94+
}
95+
8496
completion()
8597
}
8698
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "icCallkitSb.png",
5+
"idiom" : "universal",
6+
"scale" : "1x"
7+
},
8+
{
9+
"filename" : "[email protected]",
10+
"scale" : "2x",
11+
"idiom" : "universal"
12+
},
13+
{
14+
"scale" : "3x",
15+
"filename" : "[email protected]",
16+
"idiom" : "universal"
17+
}
18+
],
19+
"info" : {
20+
"version" : 1,
21+
"author" : "xcode"
22+
}
23+
}
930 Bytes
Loading
1.96 KB
Loading
3.24 KB
Loading

QuickStart/CXExtensions/CXProvider+QuickStart.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
//
77

88
import CallKit
9+
import UIKit
910

1011
extension CXProviderConfiguration {
1112
// The app's provider configuration, representing its CallKit capabilities
1213
static var `default`: CXProviderConfiguration {
13-
let providerConfiguration = CXProviderConfiguration(localizedName: "com.sendbird.calls.quickstart.cxprovider")
14-
14+
let providerConfiguration = CXProviderConfiguration(localizedName: "SendBird Calls")
15+
if let image = UIImage(named: "icCallkitSb") {
16+
providerConfiguration.iconTemplateImageData = image.pngData()
17+
}
1518
providerConfiguration.supportsVideo = false
1619
providerConfiguration.maximumCallsPerCallGroup = 1
1720
providerConfiguration.supportedHandleTypes = [.generic]

QuickStart/Extensions/UserDefaults+QuickStart.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ extension UserDefaults {
5757
}
5858
}
5959

60-
var pushToken: Data? {
60+
var voipPushToken: Data? {
6161
get {
62-
guard let pushToken = UserDefaults.standard.value(forKey: "com.sendbird.calls.quickstart.pushtoken") as? Data else { return nil }
62+
guard let pushToken = UserDefaults.standard.value(forKey: "com.sendbird.calls.quickstart.pushtoken.voip") as? Data else { return nil }
6363
return pushToken
6464
}
6565
set {
66-
UserDefaults.standard.setValue(newValue, forKey: "com.sendbird.calls.quickstart.pushtoken")
66+
UserDefaults.standard.setValue(newValue, forKey: "com.sendbird.calls.quickstart.pushtoken.voip")
6767
}
6868
}
6969
}
@@ -76,6 +76,5 @@ extension UserDefaults {
7676
UserDefaults.standard.removeObject(forKey: "com.sendbird.calls.quickstart.user.profile")
7777
UserDefaults.standard.removeObject(forKey: "com.sendbird.calls.quickstart.autologin")
7878
UserDefaults.standard.removeObject(forKey: "com.sendbird.calls.quickstart.accesstoken")
79-
UserDefaults.standard.removeObject(forKey: "com.sendbird.calls.quickstart.pushtoken")
8079
}
8180
}

QuickStart/Settings/SettingsTableViewController.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,12 @@ class SettingsTableViewController: UITableViewController {
6969
// MARK: - SendBirdCall Interaction
7070
extension SettingsTableViewController {
7171
func signOut() {
72-
guard let token = UserDefaults.standard.pushToken else { return }
72+
guard let token = UserDefaults.standard.voipPushToken else { return }
7373

7474
// MARK: SendBirdCall Deauthenticate
7575
SendBirdCall.deauthenticate(voipPushToken: token) { error in
76-
guard error == nil else { return }
77-
// Removed pushToken successfully
7876
UserDefaults.standard.clear()
77+
guard error == nil else { return }
7978
}
8079
}
8180
}

QuickStart/SignIn/SignInViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ extension SignInViewController {
7070

7171
func signIn(userId: String) {
7272
// MARK: SendBirdCall.authenticate()
73-
let params = AuthenticateParams(userId: userId, accessToken: nil, voipPushToken: UserDefaults.standard.pushToken, unique: false)
73+
let params = AuthenticateParams(userId: userId, accessToken: nil, voipPushToken: UserDefaults.standard.voipPushToken, unique: false)
7474
self.startLoading()
7575

7676
SendBirdCall.authenticate(with: params) { user, error in

0 commit comments

Comments
 (0)