From 894ee3fda0ab215c2a58e4e287983353ea86dac6 Mon Sep 17 00:00:00 2001 From: Hardik Garg <> Date: Fri, 2 Feb 2024 15:32:37 +0530 Subject: [PATCH] added key api from google service --- .../Authentication/Authentication.swift | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ios/OpenBot/OpenBot/Authentication/Authentication.swift b/ios/OpenBot/OpenBot/Authentication/Authentication.swift index 1447ea792..04d0eb755 100644 --- a/ios/OpenBot/OpenBot/Authentication/Authentication.swift +++ b/ios/OpenBot/OpenBot/Authentication/Authentication.swift @@ -130,6 +130,18 @@ class Authentication { // Show the sign-out button and hide the GIDSignInButton } } + + /** + static method to get api key from google-service + */ + static func getGoogleAPIKey() -> String { + if let path = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist"), + let dict = NSDictionary(contentsOfFile: path), + let apiKey = dict["API_KEY"] as? String { + return apiKey + } + return "" + } /** static method to download a file @@ -138,8 +150,9 @@ class Authentication { - completion: */ static func download(file: String, completion: @escaping (_ data: Data?, _ error: Error?) -> Void) { + let APIkey = getGoogleAPIKey(); let fileId = returnFileId(fileLink: file); - let url = "https://www.googleapis.com/drive/v3/files/\(fileId)?alt=media&key=AIzaSyCITlkh63TnSnJQBlzqbJwwtBDr_w3e1Pg" //key extracted from google console + let url = "https://www.googleapis.com/drive/v3/files/\(fileId)?alt=media&key=\(APIkey)"; let service: GTLRDriveService = GTLRDriveService(); let fetcher = service.fetcherService.fetcher(withURLString: url) fetcher.beginFetch(completionHandler: { data, error in @@ -162,7 +175,8 @@ class Authentication { */ static func download(fileId: String, completion: @escaping (_ data: Data?, _ error: Error?) -> Void) { - let url = "https://www.googleapis.com/drive/v3/files/\(fileId)?alt=media&key=AIzaSyCITlkh63TnSnJQBlzqbJwwtBDr_w3e1Pg" //key extracted from google console + let APIkey = getGoogleAPIKey(); + let url = "https://www.googleapis.com/drive/v3/files/\(fileId)?alt=media&key=\(APIkey)"; let service: GTLRDriveService = GTLRDriveService() let fetcher = service.fetcherService.fetcher(withURLString: url) fetcher.beginFetch(completionHandler: { data, error in