Create a Custom AdMob Plugin for Phonegap Build (for iOS and Android)

微笑、不失礼 提交于 2019-12-20 10:16:10

问题


Everything in my Phonegap Build app is working, including the Analytics and FacebookConnect plugins. However, now I would like to add AdMob ads.

Phonegap Build does not provide a built-in plugin for AdMob, but according to the Phonegap Build Plugins page, you can now add your own custom plugins (see Contributing Plugins at the bottom of the page).

PhoneGap Plugins can be made compatible with PhoneGap Build with the use of a plugin.xml file...

The Phonegap Build Plugins page references the Child Browser plugins.xml on GitHub as an example of how to setup the custom plugin.xml. Below is the content of the 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


回答1:


This is an old unanswered question as since today it was impossible. But Phonegap has announced a change in their rules: see here, so now it's possible to use external plugins. To add Admob Ads to your Phonegap Build app, edit your config.html file and place the following code:

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

I'm the author of the plugin and you can see a live demo app (for Android only) here




回答2:


I make the plugin

But it's was refused on "PhoneGap Build", because it contains Google Binary files…
Today, you don't have no solution to use Admob on "PhoneGap Build" project.




回答3:


This article has what you're looking for with regards to setting up plugman for your plugin.




回答4:


For admob: its little bit confusing reading about them, because in the past they used to serve ads through JavaScript method intended for mobile web site but after google buying the company they removed this and admob doesn't serve mobile website any more and for mobile web site they advise you to use adsense. What confusing about it that there is still instruction for installing admob JavaScript which doesn't exist any more.
I saw your links and I guess you where trying to install admob for iOS app. I did it for Android app which was straight forward and it was easy but the problem was what ever I try it shows on the bottom.




回答5:


PhoneGap Build now allows any user to contribute a plugin which will be available to all users (after a review and test ofcourse).
They have a new page describing the process and advice aspiring contributors to take a look at the repo of the Facebook plugin.

So maybe you are able to create a nice Admob plugin based on this documentation.



来源:https://stackoverflow.com/questions/14843662/create-a-custom-admob-plugin-for-phonegap-build-for-ios-and-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!