unity admob

插件地址:https://github.com/unity-plugins/Unity-Admob

 2017.04.11测试使用发现GoogleMobileAds.framework有问题,导致出现Undefined symbols for architecture等错误


以下是测试过的完整插件包:

链接:http://pan.baidu.com/s/1c1YL1mg 密码:vi8q


 无出错的GoogleMobileAds.framework:

链接:http://pan.baidu.com/s/1jHNdXNg 密码:bwyk


 unity 版本:5.6.f3

Target minimum iOS Version: 8.0

全屏广告需要在unity发布设置或xcode中把所有方向都勾上,再用代码决定要保留哪些方向,这样手持设备广告的方向才能显示正确


 

AdmobManager.cs

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using admob;

public class AdmobManager : MonoBehaviour {
    public string bannerID="ca-app-pub-3940256099942544/2934735716";
    public string fullID="ca-app-pub-3940256099942544/4411468910";
    public string rewardVideoID="ca-app-pub-3940256099942544/xxxxxxxxxx";

    public string nativeBannerID="ca-app-pub-3940256099942544/2562852117";

    Admob ad;
    private bool _isinited;

    public static AdmobManager instance {
        get{
             return GameObject.Find("AdmobManager").GetComponent<AdmobManager>();
        }
    }

    void Awake(){
        Debug.Log("start unity demo-------------");
        gameObject.name="AdmobManager";
        initAdmob();
    }
    
    void Start () {
       
    }
    
    void Update () {
        //ad.showInterstitial();
    }

    void initAdmob(){
        //isAdmobInited = true;
        ad = Admob.Instance();
        ad.bannerEventHandler += onBannerEvent;
        ad.interstitialEventHandler += onInterstitialEvent;
        ad.rewardedVideoEventHandler += onRewardedVideoEvent;
        ad.nativeBannerEventHandler += onNativeBannerEvent;
        ad.initAdmob(bannerID,fullID);
        //ad.setTesting(true);
        ad.setGender(AdmobGender.MALE);
        string[] keywords = { "game","crash","male game"};
        ad.setKeywords(keywords);
        Debug.Log("admob inited -------------");
    }

    void onInterstitialEvent(string eventName, string msg){
        Debug.Log("handler onAdmobEvent---" + eventName + "   " + msg);
        if (eventName == AdmobEvent.onAdLoaded){
            Admob.Instance().showInterstitial();
        }else if(eventName==AdmobEvent.onAdClosed){
            //Admob.Instance().loadInterstitial();
        }
    }
    void onBannerEvent(string eventName, string msg){
        Debug.Log("handler onAdmobBannerEvent---" + eventName + "   " + msg);
    }
    void onRewardedVideoEvent(string eventName, string msg){
        Debug.Log("handler onRewardedVideoEvent---" + eventName + "   " + msg);
    }
    void onNativeBannerEvent(string eventName, string msg){
        Debug.Log("handler onAdmobNativeBannerEvent---" + eventName + "   " + msg);
    }

    public bool isInterstitialReady(){
        return ad.isInterstitialReady();
    }
    public void loadInterstitial(){
        ad.loadInterstitial();
    }

    public void showInterstitial(){
        ad.showInterstitial();
    }

    public void showRewardVideo(){
        if (ad.isRewardedVideoReady()) ad.showRewardedVideo();
        else ad.loadRewardedVideo(rewardVideoID);
    }

    public void showbanner(AdSize size/*=AdSize.SmartBanner*/, int pos/*=AdPosition.BOTTOM_CENTER*/,int marginY=0){
        Admob.Instance().showBannerRelative(size, pos,marginY);
    }
    public void showbannerABS(AdSize size/*=AdSize.Banner*/,int x=0,int y=300){
        Admob.Instance().showBannerAbsolute(size, x, y);
    }
    public void removebanner(){
        Admob.Instance().removeBanner();
    }


    public void showNative(int pos/*=AdPosition.BOTTOM_CENTER*/,int width=320,int height=120,int marginY=0){
        Admob.Instance().showNativeBannerRelative(new AdSize(width,height), pos, marginY,nativeBannerID);
    }
    public void showNativeABS(int width=320,int height=120,int x=0,int y=0){
        Admob.Instance().showNativeBannerAbsolute(new AdSize(width,height), x, y, nativeBannerID);
    }
    public void removeNative(){
        Admob.Instance().removeNativeBanner();
    }

}

 

 

Editor文件夹下PBXProjectSetting.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;


public class PBXProjectSetting{

    //该属性是在build完成后,被调用的callback
    [PostProcessBuild]
    public static void OnPostprocessBuild(BuildTarget buildTarget, string path){
        // BuildTarget需为iOS
        if (buildTarget != BuildTarget.iOS) return;
        Debug.Log("===PostProcessBuildAttribute();===");

        string projPath = PBXProject.GetPBXProjectPath(path);
        PBXProject pbxProject = new PBXProject();

        pbxProject.ReadFromString(File.ReadAllText(projPath));
        string target = pbxProject.TargetGuidByName("Unity-iPhone");

        // 关闭Bitcode
        pbxProject.SetBuildProperty(target, "ENABLE_BITCODE", "NO");

        // 添加framework, admob需要的所有framework
        pbxProject.AddFrameworkToProject(target, "AdSupport.framework", false);
        pbxProject.AddFrameworkToProject(target, "EventKit.framework", false);
        pbxProject.AddFrameworkToProject(target, "EventKitUI.framework", false);
        pbxProject.AddFrameworkToProject(target, "CoreTelephony.framework", false);
        pbxProject.AddFrameworkToProject(target, "StoreKit.framework", false);
        pbxProject.AddFrameworkToProject(target, "MessageUI.framework", false);


        //保存到本地
        File.WriteAllText(projPath,pbxProject.WriteToString());
    }
}

 

转载于:https://www.cnblogs.com/kingBook/p/6693552.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值