我正在使用GADRewardedAd,我的要求是广告关闭后显示视图。在 API 版本 8 上,adDidPresentFullScreenContent() 会调用更新,但不会调用adDidDismissFullScreenContent()方法。
private var rewardedAdView: GADRewardedAd!
GADRewardedAd.load(withAdUnitID: UserDefaults.standard.string(forKey: Constants.ADMOB_KEY_AD_REWARDED) ?? "",
request: GADRequest(), completionHandler: { (ad, error) in
if let error = error {
print("Rewarded ad failed to load with error: \(error.localizedDescription)")
return
}
self.rewardedAdView = ad
self.rewardedAdView.fullScreenContentDelegate = self
}
Run Code Online (Sandbox Code Playgroud)
private func showRewardedAds(){
self.isAdEarnComplete = false
if let ad = rewardedAdView {
ad.present(fromRootViewController: self,
userDidEarnRewardHandler: {
showToast(viewContoler: self, message: "Your coupon is ready!")
}
)
}
Run Code Online (Sandbox Code Playgroud)
extension HomeViewController: GADFullScreenContentDelegate{
func adDidPresentFullScreenContent(_ …Run Code Online (Sandbox Code Playgroud) I'm working on an audiobook listening app. There I have my main page, which consists of 3 page widgets linked through a Page View that I can swipe to navigate through these pages. On each page I have laid exactly one banner ad from google_mobile_ads package. The problem is that if I add those 3 banners, my app starts to lag a lot, I did check the release version of my app, it is still laggy. In order to understand …
我正在努力在我的应用程序中实现插页式广告,但对 AdMob 提供的文档和新的 SwiftUI 应用程序结构遇到了一些困惑。
这是app.swift文件,显示我已经实现了 GoogleMobileAds 并在didFinishLaunchingWithOptions方法中启动了它。
import SwiftUI
import GoogleMobileAds
@main
struct AdamsCalcApp: App {
var calculator = Calculator()
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView().environmentObject(calculator)
}
}
}
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
// Setup Google AdMob instance
GADMobileAds.sharedInstance().start(completionHandler: nil)
return true
}
}
Run Code Online (Sandbox Code Playgroud)
在我的ContentView.swift文件中,我创建了间隙变量,如下所示:
@State var interstitial: GADInterstitialAd?
Run Code Online (Sandbox Code Playgroud)
然后,在视图的主堆栈上,我调用onAppear(perform:)加载广告:
.onAppear(perform: …Run Code Online (Sandbox Code Playgroud) 我在底部有一个可滚动的文字和广告,但是广告并没有一直到底部。尝试过RelativeLayout,但如果我使用它,则广告会停留在屏幕中间。已经玩了很多,但是似乎无法让它停留在底部并在屏幕的其余部分填充可滚动文本。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/box_background"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical">
<ScrollView
android:id="@+id/ScrollView01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:padding="30dp">
<TextView
android:id="@+id/Button_2_Text"
android:textColor="#000000"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="17dp"></TextView>
</ScrollView>
<com.google.ads.AdView
android:gravity="bottom"
xmlns:ads="http://schemas.android.com/apk/res/com.aurumlabs.excuses"
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
ads:adUnitId="a14f19b3aec0a93"
ads:adSize="BANNER"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) Ld /Users/michaelsonsamuels/Library/Developer/Xcode/DerivedData/Video-hedtrampxpseetfcmcksycqvmpuk/Build/Products/Debug-iphonesimulator/Video.app/Video normal i386
cd "/Users/michaelsonsamuels/Desktop/Xcode /Video"
setenv IPHONEOS_DEPLOYMENT_TARGET 6.1
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk -L/Users/michaelsonsamuels/Library/Developer/Xcode/DerivedData/Video-hedtrampxpseetfcmcksycqvmpuk/Build/Products/Debug-iphonesimulator -F/Users/michaelsonsamuels/Library/Developer/Xcode/DerivedData/Video-hedtrampxpseetfcmcksycqvmpuk/Build/Products/Debug-iphonesimulator -filelist /Users/michaelsonsamuels/Library/Developer/Xcode/DerivedData/Video-hedtrampxpseetfcmcksycqvmpuk/Build/Intermediates/Video.build/Debug-iphonesimulator/Video.build/Objects-normal/i386/Video.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=6.1 -framework StoreKit -framework AudioToolbox -framework MessageUI -framework SystemConfiguration -framework CoreGraphics -framework UIKit -framework Foundation -o /Users/michaelsonsamuels/Library/Developer/Xcode/DerivedData/Video-hedtrampxpseetfcmcksycqvmpuk/Build/Products/Debug-iphonesimulator/Video.app/Video
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_GADBannerView", referenced from:
objc-class-ref in ViewController.o
"_OBJC_CLASS_$_GADRequest", referenced from:
objc-class-ref in ViewController.o
"_kGADAdSizeBanner", referenced from:
-[ViewController viewDidLoad] in ViewController.o
ld: symbol(s) not found for architecture i386
clang: error: …Run Code Online (Sandbox Code Playgroud) 我使用此代码将横幅广告放在左下方.
CGPoint origin = CGPointMake(0.0,
self.view.frame.size.height -
CGSizeFromGADAdSize(kGADAdSizeBanner).height);
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner
origin:origin];
Run Code Online (Sandbox Code Playgroud)
如何将横幅定位在底部中心?
我正在尝试在我的测试应用中添加广告,当我在模拟器或设备中运行应用时,我会收到横幅添加说法Required XML attribute “adSize” was missing.
我已经设置xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"的com.google.android.gms.ads.AdView标签.
不确定如何解决此问题.
更多细节 : Android Studio AI-141.1989493
代码段:
AdView mAdView = (AdView) findViewById(R.id.adView);
mAdView.setAdSize(AdSize.BANNER);
mAdView.setAdUnitId("ca-app-pub-xxxxx/xxxxxx");
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("E58D5904AA50D88E2FD63A1D1EF97B34")
.build();
mAdView.loadAd(adRequest);
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml中
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
Run Code Online (Sandbox Code Playgroud)
activity_main.xml中
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/LinearLayout01">
<TableRow android:id="@+id/LinearLayout0">
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-xxxxx/xxxxxx"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, E58D5904AA50D88E2FD63A1D1EF97B34">
</com.google.android.gms.ads.AdView>
Run Code Online (Sandbox Code Playgroud) 今天我注册了adMob,我开始在我的应用程序中处理adMob广告.第一个是游戏(带有viewcontrollers),我想在游戏结束后立即在屏幕上显示插页式广告,所以我想在之后加载插页式广告游戏超载的视图(此视图仅在游戏结束后才可访问,游戏持续一分钟,因此不应出现太频繁)
我在youtube和admob网站上看过很多教程,我遇到了很多问题:即使我导入它也没有找到admob框架,我在构建时禁用了bitcode以避免链接器错误,但我仍然看不到测试广告在我的应用程序,在模拟器和真实设备上.
我导入了admob所需的所有框架,在xcode中我在GoogleMobileAds框架附近有一个问号,这是什么意思?关于admob的第一行是:
import GoogleMobileAds
Run Code Online (Sandbox Code Playgroud)
在viewcontroller里面
var interstitial: GADInterstitial!
func createNloadAd () -> GADInterstitial
{
var ad = GADInterstitial(adUnitID: "XXX")
var request = GADRequest()
request.testDevices = [kGADSimulatorID]
ad!.loadRequest(request)
return ad
}
Run Code Online (Sandbox Code Playgroud)
在viewdidload中
self.interstitial = self.createNloadAd()
if(self.interstitial!.isReady)
{
self.interstitial!.presentFromRootViewController(self)
self.interstitial! = self.createNloadAd()
}
Run Code Online (Sandbox Code Playgroud)
在adUnitID中,我尝试了在admob网站上创建的插页式广告的ID,以及在教程中找到的其他字符串,但都没有工作
在testdevices中,我在输出中看到消息后添加了我的iphone的UDID,但我看不到任何测试广告,我根本没有任何错误
我没有触及故事板,我是否必须在故事板中创建一些东西?
在将应用程序提交到appstore之前,我必须删除testdevices行吗?当然还有我真正的AdUnitID
也许代码是正确的,但如果应用程序没有发布,admob将无法加载,或者我可能需要等待一天才能让我的admob id开始工作
我在哪里可以找到最近的admob ID进行测试?所以我测试应用程序,如果工作我更改ID并提交
我正在使用Xcode 7.1,AdMob 7.5.2,我的应用程序部署目标是iOS7,我在带有iOS7的模拟器和iOS7的旧iPhone4上进行了测试,这应该不是问题,因为admob甚至支持iOS6
关于admob指南的另一个问题,在其他应用程序中,我可以在视图中使用iAd,在另一个应用程序中使用Admob吗?我可能会被禁止这个吗?屏幕下方只有横幅广告
我想在屏幕底部的uiableviewcontroller或uicollectionviewcontroller中添加admob。因此,我必须在uitableview控制器或uicolleectionview控制器的底部添加uiView(GAD BannerView)。那我该怎么做呢?实际上,我们可以在uiviewcontroller中轻松添加uiview,但是如何在uitableviewcontroller或uicollectionviewcontroller中添加它呢?
我只是尝试在我的布局中加入Adview.工作正常,但如果没有Internet连接则显示空格.正如我到目前为止所读到的,我理解admob的标准行为是仅在显示广告时占用空间.否则,例如.没有互联网连接,它不应该占用任何布局空间.我列出了我认为我可能犯了错误的代码,这就是我遇到这种奇怪行为的原因......
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FFFFFF"
android:weightSum="1">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="@style/AppTheme.AppBarOverlay"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<include layout="@layout/content_main"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
然后,在app gradle中:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.google.firebase:firebase-core:9.2.0'
compile 'com.google.firebase:firebase-ads:9.2.0'
}
apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud)
在模块gradle中:
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.google.gms:google-services:3.0.0'
Run Code Online (Sandbox Code Playgroud)
我想我做错了什么,所以请帮我一个建议.谢谢!