From 3c7e7ae872d2fcbf75929bfd5d6bbc4637ca6f57 Mon Sep 17 00:00:00 2001 From: kimkyuchul Date: Sun, 1 Dec 2024 14:49:30 +0900 Subject: [PATCH] =?UTF-8?q?[ADD]=20GoogleAdUnitID=20=EC=8A=A4=ED=82=B4=20?= =?UTF-8?q?=EB=B6=84=EA=B8=B0=20=EC=B2=98=EB=A6=AC=20(#150)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Projects/App/Info.plist | 2 ++ .../Sources/GoogleAds/GoogleAdsClient.swift | 10 ++++++++- .../Sources/SocialLogin/Util/APIKey.swift | 17 -------------- .../Core/Services/Sources/Util/APIKey.swift | 22 +++++++++++++++++++ 4 files changed, 33 insertions(+), 18 deletions(-) delete mode 100644 Projects/Core/Services/Sources/SocialLogin/Util/APIKey.swift create mode 100644 Projects/Core/Services/Sources/Util/APIKey.swift diff --git a/Projects/App/Info.plist b/Projects/App/Info.plist index 46770759..34c9364d 100644 --- a/Projects/App/Info.plist +++ b/Projects/App/Info.plist @@ -41,6 +41,8 @@ KAKAO_NATIVE_APP_KEY $(KAKAO_NATIVE_APP_KEY) + GOOGLE_AD_UNITID + $(GOOGLE_AD_UNITID) LSApplicationCategoryType LSApplicationQueriesSchemes diff --git a/Projects/Core/Services/Sources/GoogleAds/GoogleAdsClient.swift b/Projects/Core/Services/Sources/GoogleAds/GoogleAdsClient.swift index 5aa0400a..95fafd69 100644 --- a/Projects/Core/Services/Sources/GoogleAds/GoogleAdsClient.swift +++ b/Projects/Core/Services/Sources/GoogleAds/GoogleAdsClient.swift @@ -26,7 +26,15 @@ extension GoogleMobileAdsClient: DependencyKey { await GADMobileAds.sharedInstance().start() }, load: { - let ad = try await GADInterstitialAd.load(withAdUnitID: "ca-app-pub-3940256099942544/4411468910", request: GADRequest()) + var adUnitID: String { + #if DEBUG + return "ca-app-pub-3940256099942544/4411468910" + #else + return APIKey.googleAdUnitID + #endif + } + + let ad = try await GADInterstitialAd.load(withAdUnitID: adUnitID, request: GADRequest()) return GoogleAd(ad: ad) } diff --git a/Projects/Core/Services/Sources/SocialLogin/Util/APIKey.swift b/Projects/Core/Services/Sources/SocialLogin/Util/APIKey.swift deleted file mode 100644 index 0a9b17c7..00000000 --- a/Projects/Core/Services/Sources/SocialLogin/Util/APIKey.swift +++ /dev/null @@ -1,17 +0,0 @@ -// -// APIKey.swift -// CoreKit -// -// Created by kyuchul on 6/17/24. -// Copyright © 2024 com.jordyma.blink. All rights reserved. -// - -import Foundation - -enum APIKey { - static let kakao = { - guard let infoDictionary = Bundle.main.infoDictionary else { fatalError("Wrong Info dictionary") } - guard let key = infoDictionary["KAKAO_NATIVE_APP_KEY"] as? String else { fatalError("Wrong KAKAO_NATIVE_APP_KEY") } - return key - }() -} diff --git a/Projects/Core/Services/Sources/Util/APIKey.swift b/Projects/Core/Services/Sources/Util/APIKey.swift new file mode 100644 index 00000000..1ffdbbc3 --- /dev/null +++ b/Projects/Core/Services/Sources/Util/APIKey.swift @@ -0,0 +1,22 @@ +// +// APIKey.swift +// CoreKit +// +// Created by kyuchul on 6/17/24. +// Copyright © 2024 com.jordyma.blink. All rights reserved. +// + +import Foundation + +enum APIKey { + static let kakao = getInfoValue(for: "KAKAO_NATIVE_APP_KEY") + static let googleAdUnitID = getInfoValue(for: "GOOGLE_AD_UNITID") + + private static func getInfoValue(for key: String) -> String { + guard let infoDictionary = Bundle.main.infoDictionary, + let value = infoDictionary[key] as? String else { + fatalError("Wrong \(key)") + } + return value + } +}