forked from mirrors/linphone-iphone
Add remote push notification support, which will be required to receive and process the account creation token
This commit is contained in:
parent
6c77fe7850
commit
fd61bca29f
2 changed files with 26 additions and 1 deletions
|
|
@ -22,6 +22,8 @@ import SwiftUI
|
|||
import Firebase
|
||||
#endif
|
||||
|
||||
let accountTokenNotification = Notification.Name("AccountCreationTokenReceived")
|
||||
|
||||
class AppDelegate: NSObject, UIApplicationDelegate {
|
||||
func application(_ application: UIApplication,
|
||||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
|
||||
|
|
@ -30,6 +32,29 @@ class AppDelegate: NSObject, UIApplicationDelegate {
|
|||
#endif
|
||||
return true
|
||||
}
|
||||
|
||||
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
|
||||
let tokenStr = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
|
||||
Log.info("Received remote push token : \(tokenStr)")
|
||||
CoreContext.shared.doOnCoreQueue { core in
|
||||
Log.info("Forwarding remote push token to core")
|
||||
core.didRegisterForRemotePushWithStringifiedToken(deviceTokenStr: tokenStr + ":remote")
|
||||
}
|
||||
}
|
||||
|
||||
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
|
||||
Log.error("Failed to register for push notifications : \(error.localizedDescription)")
|
||||
}
|
||||
|
||||
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
|
||||
Log.info("debugtrace -- Received background push notification, payload = \(userInfo.description)")
|
||||
|
||||
let creationToken = (userInfo["customPayload"] as? NSDictionary)?["token"] as? String
|
||||
if let creationToken = creationToken {
|
||||
NotificationCenter.default.post(name: accountTokenNotification, object: nil, userInfo: ["token": creationToken])
|
||||
}
|
||||
completionHandler(UIBackgroundFetchResult.newData)
|
||||
}
|
||||
}
|
||||
|
||||
@main
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ class AccountLoginViewModel: ObservableObject {
|
|||
// And we ensure the account will start the registration process
|
||||
accountParams.registerEnabled = true
|
||||
accountParams.pushNotificationAllowed = true
|
||||
accountParams.remotePushNotificationAllowed = false
|
||||
accountParams.remotePushNotificationAllowed = true
|
||||
#if DEBUG
|
||||
let pushEnvironment = ".dev"
|
||||
#else
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue