반응형
이 버전에서는 TOC를 지원하지 않습니다. (ex. 모바일)
0. 사전 작업
- AdMob 계정 생성 (필수)
- 어플 앱스토어 등록 (선택)
꼭 필수는 아니지만, 사전에 어플을 먼저 앱스토어에 등록 후 AdMob 작업을 진행하는 게 훨씬 더 수월합니다.
1. 새 앱 등록
2. 광고 단위 생성
3. SDK 설치
# 해당 프로젝트로 이동
$> cd (프로젝트)
# CocoaPods 초기화 (최초 생성 시)
$> pod init
# CocoaPods 설정 추가
$> vi Podfile
...
pod 'Google-Mobile-Ads-SDK'
...
# 설치
$> pod install
4. 앱 ID 세팅
4-1. info.plist 설정
Key | Type | Value |
GADApplicationIdentifier | String | |
GADIsAdManagerApp | Boolean | YES |
Privacy - Tracking Usage Description | String | 맞춤광고를 위해 타사 광고 추적목적으로 사용됨. |
Localization native development region | String | Korea |
SKAdNetworkItems | Array | <array> <dict> <key>SKAdNetworkIdentifier</key> <string>cstr6suwn9.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>4fzdc2evr5.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>4pfyvq9l8r.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>2fnua5tdw4.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>ydx93a7ass.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>5a6flpkh64.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>p78axxw29g.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>v72qych5uu.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>ludvb6z3bs.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>cp8zw746q7.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>3sh42y64q3.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>c6k4g5qg8m.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>s39g8k73mm.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>3qy4746246.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>f38h382jlk.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>hs6bdukanm.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>v4nxqhlyqp.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>wzmmz9fp6w.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>yclnxrl5pm.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>t38b2kh725.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>7ug5zh24hu.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>gta9lk7p23.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>vutu7akeur.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>y5ghdn5j9k.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>n6fk4nfna4.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>v9wttpbfk9.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>n38lu8286q.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>47vhws6wlr.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>kbd757ywx3.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>9t245vhmpl.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>eh6m2bh4zr.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>a2p9lx4jpn.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>22mmun2rn5.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>4468km3ulz.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>2u9pt9hc89.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>8s468mfl3y.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>klf5c3l5u5.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>ppxm28t8ap.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>ecpz2srf59.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>uw77j35x4d.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>pwa73g5rt2.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>mlmmfzh3r3.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>578prtvx9j.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>4dzt52r2t5.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>e5fvkxwrpn.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>8c4e2ghe7u.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>zq492l623r.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>3rd42ekr43.skadnetwork</string> </dict> <dict> <key>SKAdNetworkIdentifier</key> <string>3qcr597p9d.skadnetwork</string> </dict> </array> |
5. 배너 적용
5.1. 초기화
import SwiftUI
import GoogleMobileAds
import AppTrackingTransparency
@main
struct iPlankApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification)) { _ in
ATTrackingManager.requestTrackingAuthorization(completionHandler: { _ in })
}
}
}
init() {
GADMobileAds.sharedInstance().start(completionHandler: nil)
// DispatchQueue 이용
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
ATTrackingManager.requestTrackingAuthorization(completionHandler: { _ in })
}
}
}
5.2. View 생성
//
// GoogleAdView.swift
// ScoreBoard
//
// Created by Royzero on 2023/09/22.
import SwiftUI
import GoogleMobileAds
struct GoogleAdView: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UIViewController {
let viewController = UIViewController()
let bannerSize = GADLandscapeAnchoredAdaptiveBannerAdSizeWithWidth(UIScreen.main.bounds.width)
let banner = GADBannerView(adSize: bannerSize)
banner.rootViewController = viewController
viewController.view.addSubview(banner)
viewController.view.frame = CGRect(origin: .zero, size: bannerSize.size)
banner.adUnitID = "ca-app-pub-" // 실제 배너 광고 단위 ID
#if DEBUG
banner.adUnitID = "ca-app-pub-3940256099942544/2934735716"
#endif
banner.load(GADRequest())
return viewController
}
func updateUIViewController(_ viewController: UIViewController, context: Context) {
}
}
struct GoogleAdView_Previews: PreviewProvider {
static var previews: some View {
GoogleAdView()
.frame(width: UIScreen.main.bounds.width, height: GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth(UIScreen.main.bounds.width).size.height)
}
}
5.2. View 적용
import SwiftUI
import GoogleMobileAds
struct ContentView: View {
...
var body: some View {
...
GoogleAdView()
.frame(width: UIScreen.main.bounds.width, height: GADLandscapeAnchoredAdaptiveBannerAdSizeWithWidth(UIScreen.main.bounds.width).size.height)
...
}
}
6. 결과 화면
대상 어플
https://apps.apple.com/us/app/planktime/id6472001393
출처
https://developers.google.com/admob/ios/quick-start?hl=ko
반응형
'개발 창고 > iOS' 카테고리의 다른 글
[SwiftUI] How to Fix a Theme with Dark or Light (0) | 2023.11.27 |
---|---|
[SwiftUI] How to Make an Array of Strings a String (0) | 2023.11.26 |
[SwiftUI] How to convert from String to CGFloat (0) | 2023.11.23 |
[SwiftUI] How to Add Google Ads Plugins (0) | 2023.10.29 |
[SwiftUI] 두 개 이상의 문자열을 합치는 방법 (0) | 2023.08.08 |