Skip to content

Commit

Permalink
Get API key from google services
Browse files Browse the repository at this point in the history
  • Loading branch information
nkalupahana committed Jan 17, 2025
1 parent 05a7c37 commit 4b7ec54
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ios/App/App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -287,6 +288,7 @@
buildActionMask = 2147483647;
files = (
F4E7D22A2D39EA4B00BED379 /* Assets.xcassets in Resources */,
F4E7D22F2D3A0AB300BED379 /* GoogleService-Info.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 15 additions & 2 deletions ios/App/Widgets/StreakWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Error>) -> 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)))
Expand Down

0 comments on commit 4b7ec54

Please sign in to comment.