iOS platform add Google ADMOB-2/2 (Unity3d Development VIII)

Source: Internet
Author: User
Tags admob

Monkey Original, welcome reprint. Reprint Please specify: reproduced from COCOS2D Development network –cocos2dev.com, thank you!

Original address: http://www.cocos2dev.com/?p=572


In the previous article, I wrote the interface implementation of iOS AdMob. So what we're going to do now is call iOS AdMob in unity and show it.

First, to achieve unity in the external interface, internal responsibility to call the iOS AdMob interface.
LHiOSAdmob.cs

Using unityengine;using system.collections;using system.runtime.interopservices;using System.Linq;using System.collections.generic;public enum gadadsize:int{//IPhone and IPod Touch ad size. Typically 320x50.kgadadsizebanner = 1,//taller version of Kgadadsizebanner. Typically 320x100.kgadadsizelargebanner,//Medium Rectangle size for the IPad (especially in a Uisplitview ' s left pane). Typically 300x250.kgadadsizemediumrectangle,//full Banner size for the IPad (especially in a uipopovercontroller or in// Uimodalpresentationformsheet). Typically 468x60.kgadadsizefullbanner,//leaderboard size for the iPad. Typically 728x90.kgadadsizeleaderboard,//skyscraper size for the iPad. Mediation only. Admob/google does not offer this size. typically//120x600.kgadadsizeskyscraper,//An ad size this spans the full width of the application in portrait orientatio N. The height is//typically pixels on an iphone/ipod UI, and all pixels tall on an iPad Ui.kgadadsizesmartbannerportrai t,//an ad size That's spans the full width of the application in landscape orientation. The height is//typically pixels on an iphone/ipod UI, and all pixels tall on an iPad ui.kgadadsizesmartbannerlandscape} public class Lhiosadmob:monobehaviour {[DllImport ("__internal")]private static extern void Startrequestadmob (string admobid, int adsizeid, float pixelx, float pixelY); [DllImport ("__internal")]private static extern void Setadmobhidden (bool ishidden);p ublic static Lhiosadmob Instance; Private gadadsize adsize;void Awake () {//singletonif (Instance! = null) {Debug.logerror ("Multiple instances of Lhiosadmob ");} Instance = this;} Init Google admob//It would request the AdMob after five seconds.//it ' s would auto show admob.public void Initadmob (str ing admobid, gadadsize size, Vector2 pos) {#if unity_iphoneint Adsizeid = (int) size;startrequestadmob (admobid, Adsizeid, p Os.x, POS.Y); #elseDebug. Log ("Admob only run on IPhone platform"); #endif}//Set Admob bannerview is visible or notpublic vo ID SetadmobvisiBLE (bool isVisible) {#if unity_iphonesetadmobhidden (!isvisible); #elseDebug. Log ("Admob only run on IPhone platform"); endif}//use of the Initializationvoid Start () {}//Update is called once per framevoid update () {}}

This is a single-instance interface class that is internally responsible for invoking the iOS AdMob interface and opening the external interface. called for other C # files.
Note: You can make a prefab and include the script. Drag and drop the prefab into the scene. Called where AdMob needs to be displayed.

Test the AdMob display, which is where you need it.

TestAdmob.cs

Using unityengine;using System.collections;public class Testadmob:monobehaviour {//Use this for initializationvoid Star T () {LHiOSAdmob.Instance.InitAdmob ("Your AdMob id", Gadadsize.kgadadsizesmartbannerlandscape, New Vector2 (0, 150));} Update is called once per framevoid update () {}}

OK, now it's time to build iOS project.

Attention:

Build iOS project, to add the corresponding compilation options and iOS framework.

1. Other Linker Flags add-OBJC

2. Xcode->targets->build Phases->link Binary with Libraries add the following frame:
Adsupport
Audiotoolbox
Avfoundation
Coregraphics
Messageui
Storekit
SystemConfiguration


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.