diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 233d85cf..c318d371 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; + 29631B9E2C96C7F600DF5916 /* PenguinNavigator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29631B9D2C96C7F600DF5916 /* PenguinNavigator.swift */; }; 301C79AE27200D9F0016307B /* OpenTokRemoteVideoFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 301C79AD27200D9F0016307B /* OpenTokRemoteVideoFactory.swift */; }; 301C79B027200DED0016307B /* OpenTokLocalVideoFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 301C79AF27200DED0016307B /* OpenTokLocalVideoFactory.swift */; }; 306FE6C8271D790C002D6EFC /* OpenTokPlatformBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 306FE6C7271D790C002D6EFC /* OpenTokPlatformBridge.swift */; }; @@ -73,6 +74,7 @@ 13E5B711BC29EB6ECCE1964C /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; + 29631B9D2C96C7F600DF5916 /* PenguinNavigator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PenguinNavigator.swift; sourceTree = ""; }; 301C79AD27200D9F0016307B /* OpenTokRemoteVideoFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenTokRemoteVideoFactory.swift; sourceTree = ""; }; 301C79AF27200DED0016307B /* OpenTokLocalVideoFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenTokLocalVideoFactory.swift; sourceTree = ""; }; 306FE6C7271D790C002D6EFC /* OpenTokPlatformBridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenTokPlatformBridge.swift; sourceTree = ""; }; @@ -186,6 +188,7 @@ 76D71B6B2C6B81B300DAFB84 /* PenguinView.swift */, 76D71B6D2C6B81CC00DAFB84 /* PenguinPlugin.swift */, 76D71B6F2C6B81EA00DAFB84 /* PenguinViewFactory.swift */, + 29631B9D2C96C7F600DF5916 /* PenguinNavigator.swift */, ); path = Penguin; sourceTree = ""; @@ -469,6 +472,7 @@ E923EFD4258645C100E3E751 /* HMG_Geofence.swift in Sources */, E923EFD62587443800E3E751 /* HMGPlatformBridge.swift in Sources */, 76D71B6C2C6B81B300DAFB84 /* PenguinView.swift in Sources */, + 29631B9E2C96C7F600DF5916 /* PenguinNavigator.swift in Sources */, 76D71B6A2C6B819000DAFB84 /* PenguinModel.swift in Sources */, 76D71B702C6B81EA00DAFB84 /* PenguinViewFactory.swift in Sources */, 301C79AE27200D9F0016307B /* OpenTokRemoteVideoFactory.swift in Sources */, diff --git a/ios/Runner/Helper/HMGPenguinInPlatformBridge.swift b/ios/Runner/Helper/HMGPenguinInPlatformBridge.swift index ccaf19ea..00383010 100644 --- a/ios/Runner/Helper/HMGPenguinInPlatformBridge.swift +++ b/ios/Runner/Helper/HMGPenguinInPlatformBridge.swift @@ -53,7 +53,6 @@ class HMGPenguinInPlatformBridge{ let penguinUIView = penguinView.view() penguinUIView.frame = mainViewController.view.bounds penguinUIView.autoresizingMask = [.flexibleWidth, .flexibleHeight] - mainViewController.view.addSubview(penguinUIView) result(nil) // Call result to indicate the method was successfully handled diff --git a/ios/Runner/Penguin/PenguinModel.swift b/ios/Runner/Penguin/PenguinModel.swift index 1676b2f9..e41979d6 100644 --- a/ios/Runner/Penguin/PenguinModel.swift +++ b/ios/Runner/Penguin/PenguinModel.swift @@ -24,6 +24,9 @@ struct PenguinModel { let isUpdateUserLocationSmoothly: Bool let isEnableReportIssue: Bool let languageCode: String + let clinicID: String + let patientID: String + let projectID: String // Initialize the model from a dictionary init?(from dictionary: [String: Any]) { @@ -42,8 +45,12 @@ struct PenguinModel { let isShowUserName = dictionary["isShowUserName"] as? Bool, let isUpdateUserLocationSmoothly = dictionary["isUpdateUserLocationSmoothly"] as? Bool, let isEnableReportIssue = dictionary["isEnableReportIssue"] as? Bool, - let languageCode = dictionary["languageCode"] as? String + let languageCode = dictionary["languageCode"] as? String, + let clinicID = dictionary["clinicID"] as? String, + let patientID = dictionary["patientID"] as? String, + let projectID = dictionary["projectID"] as? String else { + print("Initialization failed due to missing or invalid keys.") return nil } @@ -58,10 +65,12 @@ struct PenguinModel { self.positionServiceName = positionServiceName self.username = username self.isSimulationModeEnabled = isSimulationModeEnabled - self.isEnableReportIssue = isEnableReportIssue self.isShowUserName = isShowUserName self.isUpdateUserLocationSmoothly = isUpdateUserLocationSmoothly + self.isEnableReportIssue = isEnableReportIssue self.languageCode = languageCode - + self.clinicID = clinicID + self.patientID = patientID + self.projectID = projectID } } diff --git a/ios/Runner/Penguin/PenguinNavigator.swift b/ios/Runner/Penguin/PenguinNavigator.swift new file mode 100644 index 00000000..e7ce55b4 --- /dev/null +++ b/ios/Runner/Penguin/PenguinNavigator.swift @@ -0,0 +1,57 @@ +import PenNavUI +import UIKit + +class PenguinNavigator { + private var config: PenguinModel + + init(config: PenguinModel) { + self.config = config + } + + private func logError(_ message: String) { + // Centralized logging function + print("PenguinSDKNavigator Error: \(message)") + } + + func navigateToPOI( referenceId:String,completion: @escaping (Bool, String?) -> Void) { + PenNavUIManager.shared.getToken(clientID: config.clientID, clientKey: config.clientKey) { [weak self] token, error in + + if let error = error { + let errorMessage = "Token error while getting the for Navigate to method" + completion(false, "Failed to get token: \(errorMessage)") + + print("Failed to get token: \(errorMessage)") + return + } + + guard let token = token else { + completion(false, "Token is nil") + print("Token is nil") + return + } + print("Token Generated") + print(token); + + + } + } + + private func handleNavigation(referenceId: String, token: String, completion: @escaping (Bool, String?) -> Void) { + DispatchQueue.main.async { + PenNavUIManager.shared.setToken(token: token) + + PenNavUIManager.shared.navigate(to: referenceId) { [weak self] _, navError in + guard let self = self else { return } + + if let navError = navError { + self.logError("Navigation error: Reference ID invalid") + completion(false, "Navigation error: \(navError.localizedDescription)") + return + } + + // Navigation successful + completion(true, nil) + } + } + } +} diff --git a/ios/Runner/Penguin/PenguinView.swift b/ios/Runner/Penguin/PenguinView.swift index 057becf2..5cbe8260 100644 --- a/ios/Runner/Penguin/PenguinView.swift +++ b/ios/Runner/Penguin/PenguinView.swift @@ -64,7 +64,7 @@ class PenguinView: NSObject, FlutterPlatformView, PIEventsDelegate, PenNavInitia self.model = penguinModel initPenguin(args: penguinModel) } else { - print("Error: Failed to initialize PenguinModel from arguments") + print("Error: Failed to initialize PenguinModel from arguments ") } // Initialize the Penguin SDK with required configurations // initPenguin( arguments: args) @@ -82,7 +82,7 @@ class PenguinView: NSObject, FlutterPlatformView, PIEventsDelegate, PenNavInitia .setClientID(args.clientID) .setUsername(args.username) .setSimulationModeEnabled(isEnable: args.isSimulationModeEnabled) - .setBaseURL(dataURL: args.dataURL, positionURL: args.baseURL) + .setBaseURL(dataURL: args.dataURL, positionURL: args.positionURL) .setServiceName(dataServiceName: args.dataServiceName, positionServiceName: args.positionServiceName) .setIsShowUserName(args.isShowUserName) .setIsUpdateUserLocationSmoothly(args.isUpdateUserLocationSmoothly) @@ -142,8 +142,44 @@ class PenguinView: NSObject, FlutterPlatformView, PIEventsDelegate, PenNavInitia // Present the Penguin UI on top of the Flutter view controller PenNavUIManager.shared.present(root: controller, view: _view) + print("====== after present onPenNavSuccess =========") - } + print(model?.clinicID) + print("====== after present onPenNavSuccess =========") + + guard let config = self.model else { + print("Error: Config Model is nil") + return + } + + + let navigator = PenguinNavigator(config: config) + + PenNavUIManager.shared.getToken(clientID: config.clientID, clientKey: config.clientKey) { [weak self] token, error in + if let error = error { + let errorMessage = "Token error while getting the for Navigate to method" + // completion(false, "Failed to get token: \(errorMessage)") + print("Failed to get token: \(errorMessage)") + return + } + + guard let token = token else { + // completion(false, "Token is nil") + print("Token is nil") + return + } + print("Token Generated") + print(token); + PenNavUIManager.shared.setToken(token: token) + + + } + PenNavUIManager.shared.navigate(to: config.clinicID) + print("====== after Token onPenNavSuccess =========") + } + + + /** * Called when there is an initialization error with the Penguin UI. @@ -158,4 +194,8 @@ class PenguinView: NSObject, FlutterPlatformView, PIEventsDelegate, PenNavInitia print("onPenNavInitializationError: \(errorDescription)") } + + + + } diff --git a/lib/uitl/penguin_method_channel.dart b/lib/uitl/penguin_method_channel.dart index 06968bfe..9b4c142b 100644 --- a/lib/uitl/penguin_method_channel.dart +++ b/lib/uitl/penguin_method_channel.dart @@ -3,8 +3,7 @@ import 'package:flutter/services.dart'; class PenguinMethodChannel { static const MethodChannel _channel = MethodChannel('launch_penguin_ui'); - static Future launch(String storyboardName, String languageCode, String username, - {NavigationClinicDetails? details}) async { + static Future launch(String storyboardName, String languageCode, String username, {NavigationClinicDetails? details}) async { try { await _channel.invokeMethod('launchPenguin', { "storyboardName": storyboardName, @@ -16,7 +15,7 @@ class PenguinMethodChannel { "dataServiceName": "api", "positionServiceName": "pe", "clientID": "PIF", - "username": "Test", + "username": "test", "isSimulationModeEnabled": true, "isShowUserName": false, "isUpdateUserLocationSmoothly": true, @@ -24,9 +23,9 @@ class PenguinMethodChannel { "languageCode": languageCode, "clientKey": "UGVuZ3VpbklOX1Blbk5hdl9QSUY=", "mapBoxKey": "sk.eyJ1IjoicndhaWQiLCJhIjoiY2x6NWo0bTMzMWZodzJrcGZpemYzc3Z4dSJ9.uSSZuwNSGCcCdPAiORECmg", - "clinic_id": details?.clinicId ?? "", - "patient_id": details?.patientId ?? "", - "project_id": details?.projectId ?? "", + "clinicID": details?.clinicId ?? "", + "patientID": details?.patientId ?? "", + "projectID": details?.projectId ?? "", }); } on PlatformException catch (e) { print("Failed to launch PenguinIn: '${e.message}'."); @@ -34,8 +33,7 @@ class PenguinMethodChannel { } } - -class NavigationClinicDetails{ +class NavigationClinicDetails { String? clinicId; String? patientId; String? projectId;