iOS 보상형 광고
보상형 광고 노출하기
let rewardedAd = AdropRewardedAd(unitId: "PUBLIC_TEST_UNIT_ID_REWARDED")
rewardedAd.delegate = self
rewardedAd.load()
...
// 광고를 표시해야 할 경우 show 함수를 호출하세요.
rewardedAd.show(fromRootViewController: self, userDidEarnRewardHandler: { type, amount in
print("earned reward type: \(type) amount: \(amount)")
})
self.rewardedAd = [[AdropRewardedAd alloc] initWithUnitId:@"PUBLIC_TEST_UNIT_ID_REWARDED"];
self.rewardedAd.delegate = self;
[self.rewardedAd load];
...
// 광고를 표시해야 할 경우 show 함수를 호출하세요.
[self.rewardedAd showFromRootViewController:self userDidEarnRewardHandler:^(NSInteger type, NSInteger amount) {
NSLog(@"earned reward type: %ld amount: %ld", type, amount);
}];
class AdropRewardedAdWrapper: AdropRewardedAdDelegate {
var rewardedAd: AdropRewardedAd?
var errorHandler: (String) -> Void
init(_ unitId: String, handler: @escaping (String) -> Void ) {
self.rewardedAd = AdropRewardedAd(unitId: unitId)
self.errorHandler = handler
rewardedAd?.delegate = self
}
func onAdReceived(_ ad: AdropAds.AdropRewardedAd) {
print("onAdReceived")
}
func onAdFailedToReceive(_ ad: AdropAds.AdropRewardedAd, _ error: AdropAds.AdropErrorCode) {
print("onAdFailedToReceive \(AdropErrorCodeToString(code: error))")
self.errorHandler(AdropErrorCodeToString(code: error))
}
func load() {
rewardedAd?.delegate = self
rewardedAd?.load()
}
func show(fromRootViewController: UIViewController, userDidEarnRewardHandler: @escaping AdropUserDidEarnRewardHandler) {
rewardedAd?.show(fromRootViewController: fromRootViewController, userDidEarnRewardHandler:userDidEarnRewardHandler)
}
}
struct RewardedAdView: View {
@State var adropRewardedAdWrapper :AdropRewardedAdWrapper? = nil
var body: some View {
NavigationView {
VStack {
Button {
adropRewardedAdWrapper = AdropRewardedAdWrapper("PUBLIC_TEST_UNIT_ID_REWARDED") { _ in }
adropRewardedAdWrapper?.load()
} label: {
Text("load")
}
.padding(.all)
Button {
adropRewardedAdWrapper?.show(fromRootViewController: (UIApplication.shared.windows.first?.rootViewController)!){
type, amount in
print("earned reward!11(type: \(type) amount: \(amount))")
}
} label: {
Text("show")
}
.padding(.all)
Spacer()
}
.navigationTitle("RewardedAd Example")
}
}
}
Last updated