[英]iOS: Wrong instruction in installing Google Mobile Ads SDK?
I'm following this tutorial to put Google Ad on my page: https://firebase.google.com/docs/admob/ios/quick-start我正在按照本教程将 Google 广告放在我的页面上: https : //firebase.google.com/docs/admob/ios/quick-start
At the step:在步骤:
GADMobileAds.configureWithApplicationID("ca-app-pub-8123415297019784~8909888406");
And the error occurred:并且发生了错误:
AppDelegate.swift:58:9: Type 'GADMobileAds' has no member 'configureWithApplicationID'
And after the checking, i see there is no member configureWithApplicationID
.检查后,我看到没有成员
configureWithApplicationID
。
What's wrong with this instruction?这个指令有什么问题? And why i have to install Firebase/Core in this version?
为什么我必须在这个版本中安装 Firebase/Core?
Here are methods in GADMobileAds, there is no configureWithApplicationID like Objective C version.这是 GADMobileAds 中的方法,没有像 Objective C 版本那样的 configureWithApplicationID。 How stupid is that http://i.imgur.com/Od0vkPg.png
http://i.imgur.com/Od0vkPg.png是多么愚蠢
Remove the cocoapods line from the instruction and replace with this line:从指令中删除 cocoapods 行并替换为以下行:
pod 'Google-Mobile-Ads-SDK'
It will install the google sdk version 7.9.0 and you'll see the configureWithApplicationID
method.它将安装 google sdk 7.9.0 版,您将看到
configureWithApplicationID
方法。 This is the error from Google for Swift.这是 Google for Swift 的错误。
Xcode 7.3, iOS9.3.3 Xcode 7.3, iOS9.3.3
Followed the instructions above, but wanted to expand, in hopes of saving someone time.按照上面的说明操作,但想要扩展,希望能节省一些时间。 If you had 'Google-Mobile-Ads-SDK' pod already installed, then check the version to make sure it is 7.9.0+ .
如果您已经安装了“Google-Mobile-Ads-SDK”pod,请检查版本以确保它是 7.9.0+ 。 Otherwise, you will keep installing the old version over and over.
否则,您将一遍又一遍地安装旧版本。
To update the version, follow the instruction taken from Cocoapods website https://cocoapods.org/pods/Google-Mobile-Ads-SDK click "Installation Guide" (bottom right):要更新版本,请按照从 Cocoapods 网站https://cocoapods.org/pods/Google-Mobile-Ads-SDK获取的说明点击“安装指南”(右下角):
The '~> 7.9' bit will force an update. '~> 7.9' 位将强制更新。
What I had that did not work:我所拥有的不起作用:
What it needs to be:它需要是什么:
Again, note the version is 7.9.1再次注意版本是 7.9.1
The Podfile looks like this: Podfile 如下所示:
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
target 'AppName' do
# Uncomment this line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
# Pods for AppName
pod 'Firebase'
pod 'Google-Mobile-Ads-SDK', '~> 7.9'
target 'AppNameTests' do
inherit! :search_paths
# Pods for testing
end
end
Now you will be able to configure GADMobileAds with the Google prescribed method:现在,您将能够使用 Google 规定的方法配置 GADMobileAds:
[GADMobileAds configureWithApplicationID:@""];
Or the Swift equivalent:或 Swift 等价物:
GADMobileAds.configureWithApplicationID("");
Hope this helps!希望这有帮助! Cheers.
干杯。
Try to update Podfile to the following:尝试将 Podfile 更新为以下内容:
#pod 'Firebase/AdMob'
pod 'Google-Mobile-Ads-SDK'
I recently tried to update my pod to pod 'Google-Mobile-Ads-SDK', '~> 7.9'
and it did not work for me.我最近尝试将我的 pod 更新为
pod 'Google-Mobile-Ads-SDK', '~> 7.9'
但它对我不起作用。 Because I already had a version of Google-Mobile-Ads-SDK
in my file, I simply needed to run pod update
.因为我的文件中已经有一个
Google-Mobile-Ads-SDK
版本,所以我只需要运行pod update
。 The problem was that Google has updated the SDK beyond 7.9 and updating versus naming a specific version ensures you get the latest one.问题是 Google 已将 SDK 更新到 7.9 以上,并且更新与命名特定版本可确保您获得最新版本。
The instructions in the Google documentation are ok.谷歌文档中的说明没问题。 I was running into the same issue with CocoaPods installing the old version.
我在安装旧版本的 CocoaPods 时遇到了同样的问题。 Use the Cocoa Pods update command and it fetches the latest version of Admob and the error goes away.
使用 Cocoa Pods update 命令,它会获取最新版本的 Admob,错误消失。
The simplest way to import the SDK into an iOS project is to use CocoaPods.将 SDK 导入 iOS 项目的最简单方法是使用 CocoaPods。 Open your project's Podfile and add this line to your app's target:
打开您项目的 Podfile 并将此行添加到您的应用程序的目标:
pod 'Google-Mobile-Ads-SDK'
Then from the command line run:然后从命令行运行:
pod install --repo-update
If you're new to CocoaPods, see their official documentation for info on how to create and use Podfiles.如果您是 CocoaPods 的新手,请参阅他们的官方文档以获取有关如何创建和使用 Podfiles 的信息。
I see it right here in GADMobileAds.h
.我在
GADMobileAds.h
看到了它。 Check to see if you have the most up to date version.检查您是否拥有最新版本。
//
// GADMobileAds.h
// Google Mobile Ads SDK
//
// Copyright 2015 Google Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface GADMobileAds : NSObject
/// Returns the shared GADMobileAds instance.
+ (GADMobileAds *)sharedInstance;
/// Configures the SDK using the settings associated with the given application ID.
+ (void)configureWithApplicationID:(NSString *)applicationID;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.