diff --git a/ios/Runner/Helper/GlobalHelper.swift b/ios/Runner/Helper/GlobalHelper.swift index 925b89eb..c5eb7295 100644 --- a/ios/Runner/Helper/GlobalHelper.swift +++ b/ios/Runner/Helper/GlobalHelper.swift @@ -19,6 +19,18 @@ func dictionaryArray(from:String) -> [[String:Any]]{ } +func dictionary(from:String) -> [String:Any]?{ + if let data = from.data(using: .utf8) { + do { + return try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] + } catch { + print(error.localizedDescription) + } + } + return nil + +} + func showNotification(identifier:String? = nil, title:String?, subtitle:String?, message:String?, sound:UNNotificationSound = UNNotificationSound.default){ let notificationContent = UNMutableNotificationContent() diff --git a/ios/Runner/Helper/HMG_Geofence.swift b/ios/Runner/Helper/HMG_Geofence.swift index 2836cf11..0361c762 100644 --- a/ios/Runner/Helper/HMG_Geofence.swift +++ b/ios/Runner/Helper/HMG_Geofence.swift @@ -149,13 +149,20 @@ extension HMG_Geofence{ } func notifyServer(forRegion:CLRegion, transition:Transition, location:CLLocation?){ - showNotification(title: "Notifying server..." , subtitle: forRegion.identifier, message: "") - - if let idString = forRegion.identifier.split(separator: "_").first, let idInt = Int(idString){ - let body:[String:Any] = ["PointsID":idInt,"GeoType":transition.rawValue,"PatientID":"1231755"] - let url = "https://hmgwebservices.com/Services/Patients.svc/REST/GeoF_InsertPatientFileInfo" - httpPostRequest(urlString: url, jsonBody: body){ (status,json) in - showNotification(title: transition.name(), subtitle: forRegion.identifier, message: status ? "Success: notified to server ✔️" : "Failed to notified server ✖️") + if let userProfileJson = UserDefaults.standard.string(forKey: "user-profile"), + let userProfile = dictionary(from: userProfileJson), let patientId = userProfile["PatientID"] as? String{ + + if let idString = forRegion.identifier.split(separator: "_").first, let idInt = Int(idString){ + let body:[String:Any] = [ + "PointsID":idInt, + "GeoType":transition.rawValue, + "PatientID":patientId + ] + + let url = "https://hmgwebservices.com/Services/Patients.svc/REST/GeoF_InsertPatientFileInfo" + httpPostRequest(urlString: url, jsonBody: body){ (status,json) in + showNotification(title: transition.name(), subtitle: forRegion.identifier, message: status ? "Success: notified to server ✔️" : "Failed to notified server ✖️") + } } } }