diff --git a/swift/LoginTutorial/LoginTutorial.xcodeproj/project.pbxproj b/swift/LoginTutorial/LoginTutorial.xcodeproj/project.pbxproj index f50008d..5de9bd0 100644 --- a/swift/LoginTutorial/LoginTutorial.xcodeproj/project.pbxproj +++ b/swift/LoginTutorial/LoginTutorial.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 50; + objectVersion = 51; objects = { /* Begin PBXBuildFile section */ @@ -15,6 +15,7 @@ 6604168224D4606B0064FC6C /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6604168124D4606B0064FC6C /* Preview Assets.xcassets */; }; 6604168524D4606B0064FC6C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6604168324D4606B0064FC6C /* LaunchScreen.storyboard */; }; 6604168D24D4607A0064FC6C /* LoginExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6604168C24D4607A0064FC6C /* LoginExample.swift */; }; + 669AF4C124EA67BF00DA6512 /* commons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 669AF4C024EA67BF00DA6512 /* commons.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -28,6 +29,7 @@ 6604168424D4606B0064FC6C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 6604168624D4606B0064FC6C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 6604168C24D4607A0064FC6C /* LoginExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginExample.swift; sourceTree = ""; }; + 669AF4C024EA67BF00DA6512 /* commons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = commons.swift; sourceTree = ""; }; 86EBE739D84760246FCA17F1 /* Pods-LoginTutorial.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LoginTutorial.debug.xcconfig"; path = "Target Support Files/Pods-LoginTutorial/Pods-LoginTutorial.debug.xcconfig"; sourceTree = ""; }; A3C6682B4C89F9C91835CCC0 /* Pods-LoginTutorial.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LoginTutorial.release.xcconfig"; path = "Target Support Files/Pods-LoginTutorial/Pods-LoginTutorial.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -50,7 +52,6 @@ 86EBE739D84760246FCA17F1 /* Pods-LoginTutorial.debug.xcconfig */, A3C6682B4C89F9C91835CCC0 /* Pods-LoginTutorial.release.xcconfig */, ); - name = Pods; path = Pods; sourceTree = ""; }; @@ -65,6 +66,7 @@ 6604166C24D4606A0064FC6C = { isa = PBXGroup; children = ( + 669AF4BF24EA679F00DA6512 /* TutorialCommons */, 6604167724D4606A0064FC6C /* LoginTutorial */, 6604167624D4606A0064FC6C /* Products */, 0A22ADFA8AED8923D454874F /* Pods */, @@ -103,6 +105,15 @@ path = "Preview Content"; sourceTree = ""; }; + 669AF4BF24EA679F00DA6512 /* TutorialCommons */ = { + isa = PBXGroup; + children = ( + 669AF4C024EA67BF00DA6512 /* commons.swift */, + ); + name = TutorialCommons; + path = ../TutorialCommons; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -221,6 +232,7 @@ 6604167924D4606A0064FC6C /* AppDelegate.swift in Sources */, 6604167B24D4606A0064FC6C /* SceneDelegate.swift in Sources */, 6604168D24D4607A0064FC6C /* LoginExample.swift in Sources */, + 669AF4C124EA67BF00DA6512 /* commons.swift in Sources */, 6604167D24D4606A0064FC6C /* ContentView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/swift/LoginTutorial/LoginTutorial/ContentView.swift b/swift/LoginTutorial/LoginTutorial/ContentView.swift index 1b76af9..846b9a1 100644 --- a/swift/LoginTutorial/LoginTutorial/ContentView.swift +++ b/swift/LoginTutorial/LoginTutorial/ContentView.swift @@ -58,7 +58,7 @@ struct ContentView: View { } Group { Spacer() - Toggle(isOn: $tutorialContext.logsEnabled) { + Toggle(isOn: $tutorialContext.loggingUnit.logsEnabled.value) { Text("Logs collection") .multilineTextAlignment(.trailing) } diff --git a/swift/LoginTutorial/LoginTutorial/LoginExample.swift b/swift/LoginTutorial/LoginTutorial/LoginExample.swift index eae4516..18fc6a7 100644 --- a/swift/LoginTutorial/LoginTutorial/LoginExample.swift +++ b/swift/LoginTutorial/LoginTutorial/LoginExample.swift @@ -14,9 +14,7 @@ class LoginTutorialContext : ObservableObject @Published var coreVersion: String = Core.getVersion /*------------ Logs related variables ------------------------*/ - var log : LoggingService? - var logManager : LinphoneLoggingServiceManager? - @Published var logsEnabled : Bool = true + var loggingUnit = LoggingUnit() /*------------ Login tutorial related variables -------*/ var proxy_cfg: ProxyConfig? @@ -27,23 +25,14 @@ class LoginTutorialContext : ObservableObject init() { - mRegistrationDelegate.tutorialContext = self - let factory = Factory.Instance // Instanciate - - logManager = LinphoneLoggingServiceManager() - logManager!.tutorialContext = self; - log = LoggingService.Instance - log!.addDelegate(delegate: logManager!) - log!.logLevel = LogLevel.Debug - factory.enableLogCollection(state: LogCollectionState.Enabled) - // Initialize Linphone Core - try? mCore = factory.createCore(configPath: "", factoryConfigPath: "", systemContext: nil) + try? mCore = Factory.Instance.createCore(configPath: "", factoryConfigPath: "", systemContext: nil) // main loop for receiving notifications and doing background linphonecore work: mCore.autoIterateEnabled = true try? mCore.start() + mRegistrationDelegate.tutorialContext = self mCore.addDelegate(delegate: mRegistrationDelegate) // Add registration specific logs } @@ -51,20 +40,10 @@ class LoginTutorialContext : ObservableObject { if (!loggedIn) { - do { - if (proxy_cfg == nil) { - let factory = Factory.Instance - proxy_cfg = try mCore.createProxyConfig() - let address = try factory.createAddress(addr: id) - let info = try factory.createAuthInfo(username: address.username, userid: "", passwd: passwd, ha1: "", realm: "", domain: address.domain) - mCore.addAuthInfo(info: info) - try proxy_cfg!.setIdentityaddress(newValue: address) - let server_addr = "sip:" + address.domain + ";transport=tls" - try proxy_cfg!.setServeraddr(newValue: server_addr) - proxy_cfg!.registerEnabled = true + proxy_cfg = try createAndInitializeProxyConfig(core : mCore, identity: id, password: passwd) try mCore.addProxyConfig(config: proxy_cfg!) if ( mCore.defaultProxyConfig == nil) { @@ -100,17 +79,6 @@ class LoginTutorialContext : ObservableObject } -class LinphoneLoggingServiceManager: LoggingServiceDelegate { - - var tutorialContext : LoginTutorialContext! - - override func onLogMessageWritten(logService: LoggingService, domain: String, lev: LogLevel, message: String) { - if (tutorialContext.logsEnabled) - { - print("Logging service log: \(message)s\n") - } - } -} class LinphoneRegistrationDelegate: CoreDelegate {