Skip to content

Commit

Permalink
#212 ios configuration CreateIndividual and ShowDataAgreementPolicy f…
Browse files Browse the repository at this point in the history
…unction invoking

ios configuration CreateIndividual and ShowDataAgreementPolicy function invoking
  • Loading branch information
lijogeorgep authored and georgepadayatti committed Nov 16, 2023
1 parent 11467be commit 7c72820
Showing 1 changed file with 38 additions and 16 deletions.
54 changes: 38 additions & 16 deletions ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import SwiftMessages
// let navigationController = UINavigationController(rootViewController: flutterViewController)
// window.rootViewController = navigationController
// navigationController.delegate = self

let flutterChannel = FlutterMethodChannel(name: "io.igrant.data4diabetes.channel",
binaryMessenger: flutterViewController.binaryMessenger)
AriesMobileAgent.shared.configureWallet(delegate: self) { success in
Expand Down Expand Up @@ -80,9 +80,10 @@ import SwiftMessages
let userId = arguments?["userId"] as? String
let dataAgreementID = arguments?["dataAgreementID"] as? String
let baseUrl = arguments?["baseUrl"] as? String
let accessToken = arguments?["accessToken"] as? String
var data: String? = nil

PrivacyDashboard.configure(withApiKey: apiKey ?? "", withUserId: userId ?? "", withOrgId: "", withBaseUrl: String(baseUrl ?? ""), accessToken: "")
PrivacyDashboard.configure(withApiKey: apiKey ?? "", withUserId: userId ?? "", withOrgId: "", withBaseUrl: String(baseUrl ?? ""), accessToken: accessToken ?? "")
PrivacyDashboard.updateDataAgreementStatus(dataAgreementId: dataAgreementID ?? "", status: true)
PrivacyDashboard.receiveDataBackFromPrivacyDashboard = { dataReceived in
let dict = dataReceived["consentRecord"] as? [String: Any]
Expand All @@ -104,9 +105,10 @@ import SwiftMessages
let userId = arguments?["userId"] as? String
let dataAgreementID = arguments?["dataAgreementID"] as? String
let baseUrl = arguments?["baseUrl"] as? String
let accessToken = arguments?["accessToken"] as? String
var data: String? = nil

PrivacyDashboard.configure(withApiKey: apiKey ?? "", withUserId: userId ?? "", withOrgId: "", withBaseUrl: String(baseUrl?.dropLast() ?? ""), accessToken: "")
PrivacyDashboard.configure(withApiKey: apiKey ?? "", withUserId: userId ?? "", withOrgId: "", withBaseUrl: String(baseUrl ?? ""), accessToken: accessToken ?? "")
PrivacyDashboard.readDataAgreementApi(dataAgreementId: dataAgreementID ?? "") { success, resultVal in
debugPrint("Data receieved here:\(resultVal)")
let dict = resultVal["dataAgreement"] as? [String: Any]
Expand All @@ -128,9 +130,10 @@ import SwiftMessages
let userId = arguments?["userId"] as? String
let dataAgreementID = arguments?["dataAgreementID"] as? String
let baseUrl = arguments?["baseUrl"] as? String
let accessToken = arguments?["accessToken"] as? String
var data: String? = nil

PrivacyDashboard.configure(withApiKey: apiKey ?? "", withUserId: userId ?? "", withOrgId: "", withBaseUrl: String(baseUrl?.dropLast() ?? ""), accessToken: "")
PrivacyDashboard.configure(withApiKey: apiKey ?? "", withUserId: userId ?? "", withOrgId: "", withBaseUrl: String(baseUrl ?? ""), accessToken: accessToken ?? "")
PrivacyDashboard.readDataAgreementApi(dataAgreementId: dataAgreementID ?? "") { success, resultVal in
debugPrint("Data receieved here:\(resultVal)")
let dict = resultVal["dataAgreement"] as? [String: Any]
Expand All @@ -148,25 +151,44 @@ import SwiftMessages
}
case "CreateIndividual":
var data: String? = nil
let dict = ["id":"6553af58ec660dae93f6e254", "externalId": "","externalIdType":"", "identityProviderId":"", "name": "Flutter app", "iamId": "a2bd807c-fde4-40e8-8bfd-ff715d596492", "email":"[email protected]", "phone": "9876987698"]
let individualDict = ["individual": dict]
if let jsonData = try? JSONSerialization.data(withJSONObject: individualDict, options: .prettyPrinted),
let theJSONText = String(data: jsonData, encoding: String.Encoding.ascii) {
debugPrint("JSON string = \n\(theJSONText)")
data = theJSONText
let arguments = call.arguments as? [String: Any]
let apiKey = arguments?["apiKey"] as? String
let userId = arguments?["userId"] as? String
let accessToken = arguments?["accessToken"] as? String
let baseUrl = arguments?["baseUrl"] as? String

PrivacyDashboard.configure(withApiKey: apiKey ?? "", withUserId: userId ?? "", withOrgId: "", withBaseUrl: String(baseUrl ?? ""), accessToken: accessToken ?? "")
PrivacyDashboard.createAnIndividual(name: "", email: "", phone: "") { success, resultVal in
if success {
if let jsonData = try? JSONSerialization.data(withJSONObject: resultVal, options: .prettyPrinted),
let theJSONText = String(data: jsonData, encoding: String.Encoding.ascii) {
debugPrint("JSON string = \n\(theJSONText)")
data = theJSONText
}

if data != nil {
result(data)
} else {
result(FlutterError(code: "DataSharing error", message: "Error occurred. Data: \(data ?? "")", details: nil))
}
}
}
if data != nil {
result(data)
} else {
result(FlutterError(code: "DataSharing error", message: "Error occurred. Data: \(data ?? "")", details: nil))
case "ShowDataAgreementPolicy":
let arguments = call.arguments as? [String: Any]
do {
let agreement = arguments?["dataAgreementResponse"] as! String
let dict = try JSONSerialization.jsonObject(with: agreement.data(using: .utf8)!, options: []) as! [String:Any]
PrivacyDashboard.showDataAgreementPolicy(dataAgreementDic: dict)
} catch {
debugPrint(error)
}
default: break
}
})

return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
return true
}
Expand All @@ -187,7 +209,7 @@ extension AppDelegate: AriesMobileAgentDelegate{
debugPrint("Notification recieved --- \(message)")
showSuccessSnackbar(message: message,navToNotifScreen: true)
}

func showSuccessSnackbar(withTitle: String? = "", message: String,navToNotifScreen: Bool = false) {
DispatchQueue.main.async {
let success = MessageView.viewFromNib(layout: .messageView)
Expand Down

0 comments on commit 7c72820

Please sign in to comment.