Skip to content

fix: registering VoIP token when auto login process #97

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 14 additions & 2 deletions QuickStart/AppDelegate+VoIPPush.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,20 @@ extension AppDelegate: PKPushRegistryDelegate {
UserDefaults.standard.voipPushToken = pushCredentials.token
print("Push token is \(pushCredentials.token.toHexString())")

SendBirdCall.registerVoIPPush(token: pushCredentials.token, unique: true) { error in
guard error == nil else { return }
guard SendBirdCall.currentUser != nil else {
print("No logged in user.")
return
}
self.registerVoIPPushToken(token: pushCredentials.token)
}

func registerVoIPPushToken(token: Data) {
SendBirdCall.registerVoIPPush(token: token, unique: true) { error in
if let error {
print("Error registering VoIP push token: \(error.localizedDescription)")
return
}
print("Successfully registered VoIP push token.")
}
}

Expand Down
10 changes: 8 additions & 2 deletions QuickStart/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// SendBirdCall.configure(appId: appId)
// UserDefaults.standard.designatedAppId = appId

self.autoSignIn { error in
if error == nil { return }
self.autoSignIn { [weak self] error in
guard let self else { return }
if error == nil {
if let token = UserDefaults.standard.voipPushToken {
self.registerVoIPPushToken(token: token)
}
return
}
// Show SignIn controller when failed to auto sign in
self.window?.rootViewController?.present(UIStoryboard.signController(), animated: true, completion: nil)
}
Expand Down