我无法在我的Xamarin.ios中创建AdMob横幅

时间:2016-12-11 19:45:22

标签: ios firebase xamarin.ios admob

我试图在我的Xamarin iOS项目中添加AdMob横幅。你可以在下面看到我的代码。

class Student extends Model{

//attributes

private $student_id;
private $first_name;
private $last_name;
private $batch_id;

// set attributes

public function setID($student_id)
{
    $this->student_id = $student_id;
}

public function setFirstName($first_name)
{
    $this->first_name = $first_name;
}

public function setLastName($last_name)
{
    $this->last_name = $last_name;
}

public function setBatchID($batch_id)
{
    $this->batch_id = $batch_id;
}

// get attributes

public function getName()
{
    return $this->first_name." ".$this->last_name;
}

public function getID()
{
    return $this->student_id;
}

public function getBatchID()
{
    return $this->batch_id;
}

我在代码上面得到了这个输出:

  

2016-12-11 22:25:42.659 betcluev4 [9220:627724]你是   目前使用的是SDK的7.11.0版。请考虑更新   您的SDK到最新的SDK版本,以获取最新的功能和   bug修复。最新的SDK可以从.......

下载

但我已经拥有最新的Firebase SDK(7.11.0)。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

查看项目中所需的FireBase plist configurations以及下面的示例代码

  

配置

在计算机中下载了GoogleService-Info.plist文件后,请在Xamarin Studio中执行以下步骤:

GoogleService-Info.plist文件添加到您的应用项目中。

通过右键单击/构建操作将GoogleService-Info.plist构建操作行为设置为Bundle Resource

打开GoogleService-Info.plist文件,将IS_ADS_ENABLED值更改为Yes

在应用中的某处添加以下代码行,通常是在AppDelegate的FinishedLaunching方法中(不要忘记导入Firebase.Analytics命名空间):

App.Configure ();
  

示例代码

using Google.MobileAds;
const string bannerId = "<Get your ID at google.com/ads/admob>";

BannerView adView;
bool viewOnScreen = false;

public void AddBanner ()
{
    // Setup your BannerView, review AdSizeCons class for more Ad sizes. 
    adView = new BannerView (size: AdSizeCons.Banner, origin: new CGPoint (0, 0)) {
        AdUnitID = bannerId,
        RootViewController = this
    };
// Wire AdReceived event to know when the Ad is ready to be displayed
adView.AdReceived += (object sender, EventArgs e) => {
    if (!viewOnScreen) {
        View.AddSubview (adView);
        viewOnScreen = true;
    }
};

var request = Request.GetDefaultRequest ();
// Requests test ads on devices you specify. Your test device ID is printed to the console when
// an ad request is made. GADBannerView automatically returns test ads when running on a
// simulator. After you get your device ID, add it here
request.TestDevices = new [] { Request.SimulatorId.ToString () };

// Request an ad
adView.LoadRequest (request);
}