Rewarded ads are ads that users have the option of interacting with in exchange for in-app rewards . This guide shows you how to integrate rewarded ads from Ad Manager into an iOS app.
পূর্বশর্ত
- শুরু করুন নির্দেশিকাটি সম্পূর্ণ করুন।
সর্বদা পরীক্ষামূলক বিজ্ঞাপন দিয়ে পরীক্ষা করুন
আপনার অ্যাপ তৈরি এবং পরীক্ষা করার সময়, লাইভ, প্রোডাকশন বিজ্ঞাপনের পরিবর্তে পরীক্ষামূলক বিজ্ঞাপন ব্যবহার করুন। এটি না করলে আপনার অ্যাকাউন্ট সাসপেন্ড হতে পারে।
The easiest way to load test ads is to use our dedicated test ad unit ID for iOS rewarded ads:
/21775744923/example/rewarded
এটি বিশেষভাবে প্রতিটি অনুরোধের জন্য পরীক্ষামূলক বিজ্ঞাপন ফেরত দেওয়ার জন্য কনফিগার করা হয়েছে এবং কোডিং, পরীক্ষা এবং ডিবাগিংয়ের সময় আপনি এটি আপনার নিজস্ব অ্যাপে ব্যবহার করতে পারেন। আপনার অ্যাপ প্রকাশ করার আগে এটি আপনার নিজস্ব বিজ্ঞাপন ইউনিট আইডি দিয়ে প্রতিস্থাপন করুন।
For more information about how Google Mobile Ads SDK test ads work, see Test Ads .
বাস্তবায়ন
The primary steps to integrate rewarded ads are as follows:
- একটি বিজ্ঞাপন লোড করুন
- [ঐচ্ছিক] SSV কলব্যাক যাচাই করুন
- কলব্যাকের জন্য নিবন্ধন করুন
- বিজ্ঞাপনটি প্রদর্শন করুন এবং পুরষ্কার ইভেন্ট পরিচালনা করুন
একটি বিজ্ঞাপন লোড করুন
Loading an ad is accomplished using the load(adUnitID:request) method on the GADRewardedAd class.
সুইফট
func loadRewardedAd() async {
do {
rewardedAd = try await RewardedAd.load(
// Replace this ad unit ID with your own ad unit ID.
with: "/21775744923/example/rewarded", request: AdManagerRequest())
rewardedAd?.fullScreenContentDelegate = self
} catch {
print("Rewarded ad failed to load with error: \(error.localizedDescription)")
}
}
সুইফটইউআই
import GoogleMobileAds
class RewardedViewModel: NSObject, ObservableObject, FullScreenContentDelegate {
@Published var coins = 0
private var rewardedAd: RewardedAd?
func loadAd() async {
do {
rewardedAd = try await RewardedAd.load(
with: "ca-app-pub-3940256099942544/1712485313", request: Request())
rewardedAd?.fullScreenContentDelegate = self
} catch {
print("Failed to load rewarded ad with error: \(error.localizedDescription)")
}
}
অবজেক্টিভ-সি
// Replace this ad unit ID with your own ad unit ID.
[GADRewardedAd loadWithAdUnitID:@"/21775744923/example/rewarded"
request:[GAMRequest request]
completionHandler:^(GADRewardedAd *ad, NSError *error) {
if (error) {
NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
return;
}
self.rewardedAd = ad;
self.rewardedAd.fullScreenContentDelegate = self;
}];
[Optional] Validate server-side verification (SSV) callbacks
সার্ভার-সাইড যাচাইকরণ কলব্যাকে অতিরিক্ত ডেটার প্রয়োজন হয় এমন অ্যাপগুলিকে পুরস্কৃত বিজ্ঞাপনের কাস্টম ডেটা বৈশিষ্ট্য ব্যবহার করা উচিত। পুরস্কৃত বিজ্ঞাপনের বস্তুতে সেট করা যেকোনো স্ট্রিং মান SSV কলব্যাকের custom_data কোয়েরি প্যারামিটারে পাস করা হয়। যদি কোনও কাস্টম ডেটা মান সেট না করা থাকে, তাহলে custom_data কোয়েরি প্যারামিটার মান SSV কলব্যাকে উপস্থিত থাকবে না।
The following code sample demonstrates how to set custom data on a rewarded ad object before requesting an ad:
সুইফট
অবজেক্টিভ-সি
SAMPLE_CUSTOM_DATA_STRING আপনার কাস্টম ডেটা দিয়ে প্রতিস্থাপন করুন।
কলব্যাকের জন্য নিবন্ধন করুন
উপস্থাপনা ইভেন্টের বিজ্ঞপ্তি পেতে, আপনাকে অবশ্যই GADFullScreenContentDelegate কে ফেরত পাঠানো বিজ্ঞাপনের fullScreenContentDelegate প্রপার্টিতে অ্যাসাইন করতে হবে:
সুইফট
rewardedAd?.fullScreenContentDelegate = self
সুইফটইউআই
rewardedAd?.fullScreenContentDelegate = self
অবজেক্টিভ-সি
self.rewardedAd.fullScreenContentDelegate = self;
The GADFullScreenContentDelegate protocol handles callbacks for when the ad presents successfully or unsuccessfully, and when it is dismissed. The following code shows how to implement the protocol:
সুইফট
func adDidRecordImpression(_ ad: FullScreenPresentingAd) {
print("\(#function) called.")
}
func adDidRecordClick(_ ad: FullScreenPresentingAd) {
print("\(#function) called.")
}
func adWillPresentFullScreenContent(_ ad: FullScreenPresentingAd) {
print("\(#function) called.")
}
func adWillDismissFullScreenContent(_ ad: FullScreenPresentingAd) {
print("\(#function) called.")
}
func adDidDismissFullScreenContent(_ ad: FullScreenPresentingAd) {
print("\(#function) called.")
// Clear the rewarded ad.
rewardedAd = nil
}
func ad(
_ ad: FullScreenPresentingAd,
didFailToPresentFullScreenContentWithError error: Error
) {
print("\(#function) called with error: \(error.localizedDescription).")
}
সুইফটইউআই
func adDidRecordImpression(_ ad: FullScreenPresentingAd) {
print("\(#function) called")
}
func adDidRecordClick(_ ad: FullScreenPresentingAd) {
print("\(#function) called")
}
func ad(
_ ad: FullScreenPresentingAd,
didFailToPresentFullScreenContentWithError error: Error
) {
print("\(#function) called")
}
func adWillPresentFullScreenContent(_ ad: FullScreenPresentingAd) {
print("\(#function) called")
}
func adWillDismissFullScreenContent(_ ad: FullScreenPresentingAd) {
print("\(#function) called")
}
func adDidDismissFullScreenContent(_ ad: FullScreenPresentingAd) {
print("\(#function) called")
// Clear the rewarded ad.
rewardedAd = nil
}
অবজেক্টিভ-সি
- (void)adDidRecordImpression:(id<GADFullScreenPresentingAd>)ad {
NSLog(@"%s called", __PRETTY_FUNCTION__);
}
- (void)adDidRecordClick:(id<GADFullScreenPresentingAd>)ad {
NSLog(@"%s called", __PRETTY_FUNCTION__);
}
- (void)adWillPresentFullScreenContent:(id<GADFullScreenPresentingAd>)ad {
NSLog(@"%s called", __PRETTY_FUNCTION__);
}
- (void)adWillDismissFullScreenContent:(id<GADFullScreenPresentingAd>)ad {
NSLog(@"%s called", __PRETTY_FUNCTION__);
}
- (void)adDidDismissFullScreenContent:(id<GADFullScreenPresentingAd>)ad {
NSLog(@"%s called", __PRETTY_FUNCTION__);
// Clear the rewarded ad.
self.rewardedAd = nil;
}
- (void)ad:(id)ad didFailToPresentFullScreenContentWithError:(NSError *)error {
NSLog(@"%s called with error: %@", __PRETTY_FUNCTION__, error.localizedDescription);
}
বিজ্ঞাপনটি প্রদর্শন করুন এবং পুরষ্কার ইভেন্ট পরিচালনা করুন
Before displaying a rewarded ad to users, you must present the user with an explicit choice to view rewarded ad content in exchange for a reward. Rewarded ads must always be an opt-in experience.
When presenting your ad, you must provide a GADUserDidEarnRewardHandler object to handle the reward for the user.
নিম্নলিখিত কোডটি পুরস্কৃত বিজ্ঞাপন প্রদর্শনের সর্বোত্তম পদ্ধতি উপস্থাপন করে:
সুইফট
rewardedAd.present(from: self) {
let reward = rewardedAd.adReward
print("Reward received with currency \(reward.amount), amount \(reward.amount.doubleValue)")
// TODO: Reward the user.
}
সুইফটইউআই
Listen to UI events in the view to determine when to show the ad.
var body: some View {
VStack(spacing: 20) {
Button("Watch video for additional 10 coins") {
viewModel.showAd()
showWatchVideoButton = false
}
ভিউ মডেল থেকে পুরস্কৃত বিজ্ঞাপনটি উপস্থাপন করুন:
func showAd() {
guard let rewardedAd = rewardedAd else {
return print("Ad wasn't ready.")
}
rewardedAd.present(from: nil) {
let reward = rewardedAd.adReward
print("Reward amount: \(reward.amount)")
self.addCoins(reward.amount.intValue)
}
}
অবজেক্টিভ-সি
[self.rewardedAd presentFromRootViewController:self
userDidEarnRewardHandler:^{
GADAdReward *reward = self.rewardedAd.adReward;
NSString *rewardMessage = [NSString
stringWithFormat:@"Reward received with currency %@ , amount %lf",
reward.type, [reward.amount doubleValue]];
NSLog(@"%@", rewardMessage);
// TODO: Reward the user.
}];
প্রায়শই জিজ্ঞাসিত প্রশ্নাবলী
- আমি কি
GADRewardedAdএর পুরষ্কারের বিবরণ পেতে পারি? - Yes, if you need the reward amount before the
userDidEarnRewardcallback is fired,GADRewardedAdhas anadRewardproperty that you can check to verify the reward amount after the ad has loaded. - ইনিশিয়ালাইজেশন কলের জন্য কি কোন টাইমআউট আছে?
- After 10 seconds, Google Mobile Ads SDK invokes the
GADInitializationCompletionHandlerprovided to thestartWithCompletionHandler:method, even if a mediation network still hasn't completed initialization. - What if some mediation networks aren't ready when I get the initialization callback?
We recommend loading an ad inside the
GADInitializationCompletionHandler. Even if a mediation network is not ready, Google Mobile Ads SDK still asks that network for an ad. So if a mediation network finishes initializing after the timeout, it can still service future ad requests in that session.আপনি
GADMobileAds.initializationStatusএ কল করে আপনার অ্যাপ সেশন জুড়ে সমস্ত অ্যাডাপ্টারের ইনিশিয়ালাইজেশন স্ট্যাটাস পোল করা চালিয়ে যেতে পারেন।- একটি নির্দিষ্ট মধ্যস্থতা নেটওয়ার্ক কেন প্রস্তুত নয় তা আমি কীভাবে খুঁজে পাব?
GADAdapterStatusঅবজেক্টেরdescriptionবৈশিষ্ট্যটি বর্ণনা করে যে কেন একটি অ্যাডাপ্টার বিজ্ঞাপনের অনুরোধগুলি পরিষেবা দেওয়ার জন্য প্রস্তুত নয়।-
userDidEarnRewardHandlerকমপ্লিশন হ্যান্ডলার কি সবসময়adDidDismissFullScreenContent:ডেলিগেট পদ্ধতির আগে কল করা হয়? Google বিজ্ঞাপনের ক্ষেত্রে, সমস্ত
userDidEarnRewardHandlerকলadDidDismissFullScreenContent:এর আগে ঘটে। মধ্যস্থতার মাধ্যমে পরিবেশিত বিজ্ঞাপনের ক্ষেত্রে, তৃতীয় পক্ষের বিজ্ঞাপন নেটওয়ার্ক SDK এর বাস্তবায়ন কলব্যাকের ক্রম নির্ধারণ করে। যেসব বিজ্ঞাপন নেটওয়ার্ক SDK পুরষ্কারের তথ্য সহ একটি একক প্রতিনিধি পদ্ধতি প্রদান করে, তাদের ক্ষেত্রে মধ্যস্থতা অ্যাডাপ্টারadDidDismissFullScreenContent:এর আগেuserDidEarnRewardHandlerআহ্বান করে।
GitHub-এ উদাহরণ
আপনার পছন্দের ভাষায় সম্পূর্ণ পুরস্কৃত বিজ্ঞাপনের উদাহরণ দেখুন:
পরবর্তী পদক্ষেপ
ব্যবহারকারীর গোপনীয়তা সম্পর্কে আরও জানুন।