效果视频:
教程:
1.1 DotNet MAUI项目安装iOS nuget包
NuGet\Install-Package Net.MAUILibrary.iOS.GoogleMobileAds -Version 11.13.0.1
1.2 如果使用模拟器进行测试可以安装以下nugget包
NuGet\Install-Package Net.MAUILibrary.iOS.GoogleMobileAds.Simulator -Version 11.13.0
2.1 配置info.plist
在info.plist设置GADApplicationIdentifier及SKAdNetworkItems,示例:
<key>GADApplicationIdentifier</key>
<string>ca-app-pub-3940256099942544~1458002511</string>
<key>SKAdNetworkItems</key>
<array>
<dict>
<key>SKAdNetworkIdentifier</key>
<string>cstr6suwn9.skadnetwork</string>
</dict>
</array>
2.参考官方文档原生源码用法对照调用C#相应函数;
示例代码在MainPage.xaml.cs使用了Interstitial Ad为例:
public MainPage()
{
InitializeComponent();
GADMobileAds.SharedInstance.StartWithCompletionHandler(null);
GAMRequest request=GAMRequest.Request() as GAMRequest;
GAMInterstitialAd.LoadWithAdManagerAdUnitID(
"/21775744923/example/interstitial",
request!,
(ad,error)=>
{
if(error!=null)
{
Debug.WriteLine("Detect Google Ads Error:"+error.LocalizedDescription);
}
else
{
ad.PresentFromRootViewController(null);
}
});
#endif
}
其他资料:
官方文档 - Get Started
https://developers.google.com/ad-manager/mobile-ads-sdk/ios/quick-start
官方文档 - Interstitial
https://developers.google.com/ad-manager/mobile-ads-sdk/ios/interstitial
Github示例代码
https://github.com/jingliancui/MAUIiOSGoogleMobileAdsSampleApp