-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ef6fa4
commit 905a37d
Showing
7 changed files
with
284 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// Opening.swift | ||
// D3N | ||
// | ||
// Created by 송영모 on 12/5/23. | ||
// Copyright © 2023 sju. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
import GoogleMobileAds | ||
import UIKit | ||
|
||
public final class AppOpenAds: NSObject { | ||
let id: String | ||
var ad: GADAppOpenAd? | ||
|
||
var completion: (() -> Void)? | ||
|
||
public init(id: String) { | ||
self.id = id | ||
super.init() | ||
load() | ||
} | ||
|
||
private func load(){ | ||
let request = GADRequest() | ||
|
||
GADAppOpenAd.load( | ||
withAdUnitID: id, | ||
request: request, | ||
completionHandler: { [self] ad, error in | ||
if let error = error { | ||
print("Failed to load rewarded ad with error: \(error.localizedDescription)") | ||
return | ||
} | ||
print("Rewarded ad loaded.") | ||
self.ad = ad | ||
self.show { } | ||
} | ||
) | ||
} | ||
|
||
public func show(completion: @escaping () -> Void){ | ||
self.completion = completion | ||
|
||
if let ad = ad, | ||
let root = (UIApplication.shared.connectedScenes.first as? UIWindowScene)?.windows.first?.rootViewController { | ||
ad.present(fromRootViewController: root) | ||
self.completion?() | ||
} else { | ||
print("Ad wasn't ready") | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters