From b2bc5b1b1259769b6842ea9d94d17a3526b91ffd Mon Sep 17 00:00:00 2001 From: QuentinArguillere Date: Thu, 29 Jul 2021 11:28:46 +0200 Subject: [PATCH] Update createAndInitializeAccount common function for easier push settings understanding --- .../CallKitTutorial/CallKitTutorial/CallExample.swift | 10 ++-------- swift/TutorialCommons/commons.swift | 9 +++++++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/swift/CallKitTutorial/CallKitTutorial/CallExample.swift b/swift/CallKitTutorial/CallKitTutorial/CallExample.swift index 17bd842..fb2daf7 100644 --- a/swift/CallKitTutorial/CallKitTutorial/CallExample.swift +++ b/swift/CallKitTutorial/CallKitTutorial/CallExample.swift @@ -66,14 +66,8 @@ class CallKitExampleContext : ObservableObject func createAccountAndRegister() { if (!loggedIn) { do { - account = try createAndInitializeAccount(core : mCore, identity: id, password: passwd) - - // This is necessary to register to the server and handle push Notifications. Make sure you have a certificate to match your app's bundle ID. - let updatedPushParams = account.params?.clone() - updatedPushParams?.pushNotificationConfig?.provider = "apns.dev" - updatedPushParams?.pushNotificationAllowed = true - account.params = updatedPushParams - + account = try createAndInitializeAccount(core : mCore, identity: id, password: passwd, withVoipPush: true) + try mCore.addAccount(account: account!) if ( mCore.defaultAccount == nil) { // IMPORTANT : default account setting MUST be done AFTER adding the config to the core ! diff --git a/swift/TutorialCommons/commons.swift b/swift/TutorialCommons/commons.swift index 3bf48cc..6a3ab27 100644 --- a/swift/TutorialCommons/commons.swift +++ b/swift/TutorialCommons/commons.swift @@ -6,7 +6,7 @@ import Foundation import linphonesw -func createAndInitializeAccount(core: Core, identity: String, password: String) throws -> Account { +func createAndInitializeAccount(core: Core, identity: String, password: String, withVoipPush: Bool = false, withRemotePush: Bool = false) throws -> Account { let factory = Factory.Instance let accountParams = try core.createAccountParams() let address = try factory.createAddress(addr: identity) @@ -16,6 +16,11 @@ func createAndInitializeAccount(core: Core, identity: String, password: String) try accountParams.setServeraddr(newValue: "sip:" + address.domain + ";transport=tls") accountParams.registerEnabled = true + // This is necessary to register to the server and handle push Notifications. Make sure you have a certificate to match your app's bundle ID. + accountParams.pushNotificationConfig?.provider = "apns.dev" + + accountParams.pushNotificationAllowed = withVoipPush + accountParams.remotePushNotificationAllowed = withRemotePush core.addAuthInfo(info: info) return try core.createAccount(params: accountParams) } @@ -39,7 +44,7 @@ class LoggingUnit var logsEnabled : BoolHolder! func onLogMessageWritten(logService: LoggingService, domain: String, level: LogLevel, message: String) { if (logsEnabled.value) { - print("Linphone logs: \(message)\n") + print("Linphone logs: \(message)") } } }