How to embed AdMob ads into your HTML5 iOS game using the PHONEGAP program

Source: Internet
Author: User
Tags admob

If you don't have an AdMob account, sign up for an AdMob account first.

Click on the "Monetize new app" button.

If it is a new application that you still want to publish, select the "Add your app manually" tab, name your app, select Platform–ios in this case, and then click "Add App" to select the ad form, like you showed how to create an interstitial ad, Give it a name and save it, and the process is the same as the banner. You should add them.

Write down your ad unit ID, and if you don't have one, create a banner ad type. You should end up with an ID of two ad units, one for the banner and the other for the interrupt.

Some concepts of time switching to terminals and applications have been from HTML5 to iOS and phonegap local games, starting with project creation:
PhoneGap Create demo Com.admob.appdemo

Once the item is created, move it to the folder.
CD Demo

Then install the AdMob plugin.
PhoneGap Plugin Add AdMob

The plugin "AdMob Plugin Pro" will be installed automatically.

Add your HTML5 game as shown in the previous step and start.
PhoneGap build iOS

The Xcode project is ready.

Finally, open Xcode and check to see if the plugin is properly installed, and check the "Plugins" and "config" files in the "Staging" file.

<uses-permission android:name= "Android.permission.INTERNET"/>
<uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name= "Android.permission.ACCESS_WIFI_STATE"/>

With the latest version of PhoneGap, the plug-in listed in CONFIG. * is a "feature" and the previous list is "plug-ins".

Now we are ready to include banners and interstitial ads into our game, but we need to be aware of several code tricks: first, in the index.html file, you should include calling Cordova.js. This is my game made in Phaser:
Admob.initadmob ("AdMob banner id", "AdMob interstitial id");

The game itself should set a "Device Ready" event listener, as follows:
Document.addeventlistener (AdMob.    Event.oninterstitialreceive, oninterstitialreceive, false); Show in AD receive event fun need add receive listener
Admob.cacheinterstitial (); Load AdMob Interstitial
function oninterstitialreceive (message) {//show in AD receive event fun
Admob.showinterstitial ();
}

function Ongameover () {//call This-fun-show when game-over
Admob.isinterstitialready (function (isReady) {
if (IsReady) {
Admob.showinterstitial ();
}
});
}

Display a banner, using the Createbanner method:
Admob.showbannerabsolute (AdMob. BANNERSIZE.BANNER,0,70);

See how to look at the simulator.
First create a slot that is necessary at the beginning of the level to preload for a period of time
function onadmobevent (message) {
Do some on AdMob event
}

Document.addeventlistener (AdMob. Event.onbannerdismiss, Onadmobevent, false);
Document.addeventlistener (AdMob. Event.onbannerfailedreceive, Onadmobevent, false);
Document.addeventlistener (AdMob. Event.onbannerleaveapplication, Onadmobevent, false);
Document.addeventlistener (AdMob. Event.onbannerpresent, Onadmobevent, false);
Document.addeventlistener (AdMob. Event.onbannerreceive, Onadmobevent, false);
Document.addeventlistener (AdMob. Event.oninterstitialdismiss, Onadmobevent, false);
Document.addeventlistener (AdMob. Event.oninterstitialfailedreceive, Onadmobevent, false);
Document.addeventlistener (AdMob. Event.oninterstitialleaveapplication, Onadmobevent, false);
Document.addeventlistener (AdMob. Event.oninterstitialpresent, Onadmobevent, false);
Document.addeventlistener (AdMob. Event.oninterstitialreceive, Onadmobevent, false);

Then show.
Admob.showinterstitial ();

Now you can use AdMob ads to add HTML5 games to iOS and PhoneGap.

How to embed AdMob ads into your HTML5 iOS game using the PHONEGAP program

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.