From 4b7ec5470907a69812f8c4815be6549c200d8451 Mon Sep 17 00:00:00 2001 From: nkalupahana Date: Fri, 17 Jan 2025 09:24:05 +0530 Subject: [PATCH] Get API key from google services --- ios/App/App.xcodeproj/project.pbxproj | 4 ++++ ios/App/Widgets/StreakWidget.swift | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/ios/App/App.xcodeproj/project.pbxproj b/ios/App/App.xcodeproj/project.pbxproj index 99abba7b..0654a044 100644 --- a/ios/App/App.xcodeproj/project.pbxproj +++ b/ios/App/App.xcodeproj/project.pbxproj @@ -25,6 +25,7 @@ F4E7D22A2D39EA4B00BED379 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F4E7D2252D39EA4B00BED379 /* Assets.xcassets */; }; F4E7D22C2D39EA4B00BED379 /* StreakWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4E7D2272D39EA4B00BED379 /* StreakWidget.swift */; }; F4E7D22D2D39EA4B00BED379 /* WidgetsBundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4E7D2282D39EA4B00BED379 /* WidgetsBundle.swift */; }; + F4E7D22F2D3A0AB300BED379 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = F43DAABF27C57A7C00566D61 /* GoogleService-Info.plist */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -287,6 +288,7 @@ buildActionMask = 2147483647; files = ( F4E7D22A2D39EA4B00BED379 /* Assets.xcassets in Resources */, + F4E7D22F2D3A0AB300BED379 /* GoogleService-Info.plist in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -563,6 +565,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = ""; "DEVELOPMENT_TEAM[sdk=iphoneos*]" = FC733RM99L; ENABLE_USER_SCRIPT_SANDBOXING = YES; @@ -605,6 +608,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = ""; "DEVELOPMENT_TEAM[sdk=iphoneos*]" = FC733RM99L; ENABLE_USER_SCRIPT_SANDBOXING = YES; diff --git a/ios/App/Widgets/StreakWidget.swift b/ios/App/Widgets/StreakWidget.swift index 35731091..2c334ce3 100644 --- a/ios/App/Widgets/StreakWidget.swift +++ b/ios/App/Widgets/StreakWidget.swift @@ -10,13 +10,26 @@ import SwiftUI struct Provider: TimelineProvider { + func getAPIKey() -> String? { + if let path = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist") { + if let plistContent = NSDictionary(contentsOfFile: path) as? [String: Any] { + return plistContent["API_KEY"] as? String + } + } + return nil + } + func refreshToken(completion: @escaping (Result) -> Void) { - let url = URL(string: "https://securetoken.googleapis.com/v1/token?key=AIzaSyCtzcuoGrYQfj-PaXGLNTD22Ro0JecPLl4")! + guard let apiKey = getAPIKey() else { + completion(.failure(NSError(domain: "NoApiKey", code: -4))) + return + } + + let url = URL(string: "https://securetoken.googleapis.com/v1/token?key=\(apiKey)")! var request = URLRequest(url: url) request.httpMethod = "POST" request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") - let userDefaults = UserDefaults.init(suiteName: "group.app.getbaseline.baseline")! guard let refreshToken = userDefaults.string(forKey: "refreshToken") else { completion(.failure(NSError(domain: "NoData", code: -3)))