首页 文章

为Phonegap Build创建自定义AdMob插件(适用于iOS和Android)

提问于
浏览
46

我的Phonegap Build应用程序中的所有内容都在运行,包括Analytics和FacebookConnect插件 . 但是,现在我想添加AdMob广告 .

Phonegap Build不为AdMob提供内置插件,但根据Phonegap Build Plugins page,您现在可以添加自己的自定义插件(请参阅页面底部的Contributing Plugins) .

使用plugin.xml文件可以使PhoneGap插件与PhoneGap Build兼容...

Phonegap Build Plugins页面引用Child Browser plugins.xml on GitHub作为如何设置自定义plugin.xml的示例 . 以下是Child Browser plugin.xml的内容 .

I'm not sure what aspects of this file I need to modify and what to modify them to. I think I have correctly setup the file structure of the Phonegap AdMob Plugins for both iOS and Android (see the file structure below), but I'm not sure how to reference these files correctly in the plugin.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
    xmlns:android="http://schemas.android.com/apk/res/android"
    id="com.phonegap.plugins.childbrowser"
    version="3.0.4">

    <name>Child Browser</name>

    <asset src="www/childbrowser.js" target="childbrowser.js" />
    <asset src="www/childbrowser" target="childbrowser" />

    <!-- android -->
    <platform name="android">
        <config-file target="AndroidManifest.xml" parent="/manifest/application">
            <activity android:name="com.phonegap.plugins.childBrowser.ChildBrowser"
                      android:label="@string/app_name">
                <intent-filter>
                </intent-filter>
            </activity>
        </config-file>

        <!-- Cordova 1.5 - 1.9 -->
        <config-file target="res/xml/plugins.xml" parent="/plugins">
            <plugin name="ChildBrowser"
                value="com.phonegap.plugins.childBrowser.ChildBrowser"/>
        </config-file>

        <!-- Cordova 2.0.0 -->
        <config-file target="res/xml/config.xml" parent="/cordova/plugins">
            <plugin name="ChildBrowser"
                value="com.phonegap.plugins.childBrowser.ChildBrowser"/>
        </config-file>

        <source-file src="src/android/ChildBrowser.java"
                target-dir="src/com/phonegap/plugins/childBrowser" />
    </platform>
    <!-- ios -->
    <platform name="ios">
        <plugins-plist key="ChildBrowser"
                    string="ChildBrowserCommand" />

        <resource-file src="ChildBrowser.bundle" />
        <resource-file src="ChildBrowserViewController.xib" />

        <header-file src="ChildBrowserCommand.h" />
        <header-file src="ChildBrowserViewController.h" />

        <source-file src="ChildBrowserCommand.m" />
        <source-file src="ChildBrowserViewController.m" />
    </platform>
</plugin>

App File Structure

/index.html 
/config.xml 
  /adMob 
    /plugin.xml 
    /src
      /iOS 
        /GADAdMobExtras.h (from AdMob iOS SDK)
        /GADAdNetworkExtras.h (from AdMob iOS SDK)
        /GADAdSize.h (from AdMob iOS SDK)
        /GADBannerView.h (from AdMob iOS SDK)
        /GADBannerViewDelegate.h (from AdMob iOS SDK)
        /GADInterstitial.h (from AdMob iOS SDK)
        /GADInterstitialDelegate.h (from AdMob iOS SDK)
        /GADRequest.h (from AdMob iOS SDK)
        /GADRequestError.h (from AdMob iOS SDK)
        /libGoogleAdMobAds.a (from AdMob iOS SDK)
        /AdMobPlugin.h (from Phonegap Plugin for iOS)
        /AdMobPlugin.js (from Phonegap Plugin for iOS)
        /AdMobPlugin.m (from Phonegap Plugin for iOS)
      /android
        /AdMobPlugin.java (from Phonegap Plugin for Android)
        /AdMobPlugin.js (from Phonegap Plugin for Android)
        /GoogleAdMobAdsSdk-6.2.1.jar (from AdMob Android SDK)

Phonegap Plugin for iOS
AdMob iOS SDK
Phonegap Plugin for Android
AdMob Android SDK

5 回答

  • 2

    这是一个尚未解决的问题,因为从今天开始这是不可能的 . 但是Phonegap已宣布改变他们的规则:see here,所以现在可以使用外部插件了 . 要将Admob广告添加到您的Phonegap Build应用,请编辑 config.html 文件并放置以下代码:

    <gap:plugin name="phonegap-admob" source="npm" />
    

    我是该插件的作者,你可以看到一个现场演示应用程序(仅适用于Android)here

  • 0

    我做plugin

    但它在"PhoneGap Build"被拒绝,因为它包含谷歌二进制文件......
    今天,您没有在"PhoneGap Build"项目上使用Admob的解决方案 .

  • 0

    This article有关于为插件设置插件的所需内容 .

  • 0

    对于admob:它有点令人困惑地阅读它们,因为过去他们曾经通过用于移动网站的JavaScript方法提供广告,但谷歌购买公司后他们删除了这个并且admob不再存在 .
    我看到了你的链接,我猜你在哪里试图为iOS应用程序安装admob . 我是为Android应用程序做的,这是直接的,它是easy但问题是我尝试它显示在底部 .

  • 3

    PhoneGap Build现在允许任何用户提供一个插件,供所有用户使用(在审查和测试之后) .
    他们有一个新页面描述了流程,并建议有抱负的贡献者来看看Facebook插件的回购 .

    所以也许你可以基于this documentation创建一个不错的Admob插件 .

相关问题