AI Integration Agent Instructions for Rewarded Ads
Gotchas
Google Mobile Ads SDK uses NS_SWIFT_NAME macros to provide idiomatic Swift
names.
Rewarded ad workflow
Load the ad
- For Swift code, use
async/awaitinstead of a completion handler.
- For Swift code, use
Register for ad event callbacks
- Set the
fullScreenContentDelegateon theRewardedAdobject.- Drop the reference to the rewarded ad when the ad is dismissed or fails to show.
- Set the
Add a UI element to view the ad for a reward
- Rewarded ads must never be shown automatically. Users must explicitly opt in.
- Add a UI element, such as a button, that shows the ad upon user interaction.
Show the ad
- ViewController Parameter: The
rootViewControllerparameter in thepresent(from:)method is an optional parameter and can be set tonil. - The
present(from:)method requires aUserDidEarnRewardHandlerobject.
- ViewController Parameter: The
Verify the implementation: Verify the build to ensure there are no compile errors:
- If
xcodebuildis available: Runxcodebuildto programmatically verify that the iOS project compiles properly with the GMA SDK. Resolve any GMA-SDK related compile errors. - If
xcodebuildis NOT available: Output instructions directing the user to build the project in Xcode and manually verify there are no compile errors.
- If
Links
Additional documentation: