Config.xcconfig を作成
プロジェクトのInfo.plistに読み込めるように追記する
<key>GOOGLE_API_KEY</key>
<string>$(GOOGLE_API_KEY)</string>
Config.xcconfigファイルを読み込めるように登録する
Configurations
のDebug
やRelease
にConfig.xcconfigファイル
を登録する
読み込み処理の実装例
AppDelegate.swift
//
// AppDelegate.swift
// OCR_TestApp
//
import Foundation
import UIKit
import GoogleSignIn
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Initialize sign-in
if let apikey = Bundle.main.object(forInfoDictionaryKey: "GOOGLE_API_KEY") as? String {
print("API Key: \(apikey)")
// Google Sign-Inの初期化
GIDSignIn.sharedInstance.configuration = GIDConfiguration(clientID: apikey)
return true
} else {
print("API Key not found")
return false
}
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
return GIDSignIn.sharedInstance.handle(url)
}
}
読み込みに使用しているコード
Bundle.main.object(forInfoDictionaryKey: "GOOGLE_API_KEY")