设为首页 收藏本站
查看: 1318|回复: 0

Windows Phone 7 For XNA 广告盈利

[复制链接]

尚未签到

发表于 2015-5-8 12:36:58 | 显示全部楼层 |阅读模式
    “Adcertising Services”广告服务控件是微软在Windows Phone平台上推出的赚钱利器,Adcertising Services可以轻松的帮助开发者在其开发的应用程序或者XNA游戏上显示广告。
  

  

使用步骤
  A)下载Microsoft Adcertising SDK for Windows Phone,并安装。安装完成后会你会得到两个框架的组件,一个是基于SL的,一个是基于XNA的。
  B) 登陆PubCenter,PubCenter主要的功能是创建并管理您的广告。在PubCenter中微软提供了贴心的广告解决方案帮你管理你的应用程序中广告的显示次数,盈利分析等功能。需要注意的是,登陆PubCenter时最好使用IE8.0或火狐5.0以上版本登陆,用其他浏览器登陆时会出现浏览器兼容问题。
  C) 创建并提交。
  

  

使用流程

  A)注册
  1)开打PubCenter后,使用你的开发者账号登陆。如下图:
  

DSC0000.jpg DSC0001.jpg
  2)如果你登陆成功的话,恭喜你,你已经离成功不远了 :)。登陆成功后你将完成注册Application ID、Ad units ID等工作。如下图:
  

DSC0002.jpg
  
           Reports:报表,这里主要表述了你的盈利情况,也可以查看广告不同时期的盈利,当然你还可以根据自己的需求来创建一个报表并保存。
           Setup:创建广告的入口,下面会详细列出步骤。
         Accounts:开发者账号个人信息。
        3)创建你的广告,点击Setup将会出现下图
DSC0003.jpg
                     Applications:用来创建你的应用程序ID。
          Ad units:用来创建你广告单元的ID。
          Global ad exclusions:全球广告排除。添加你要阻止的URL。
          Channels:广告渠道。
          点击Applications->点击Register application,见下图:
        
DSC0004.jpg
DSC0005.jpg
          Name:因为是测试用,所有名字可以随意起:)
          Device type:选不了,默认!
  

                     点击Save进行保存来到下个页面。如下图:
  

DSC0006.jpg
  
  接下来该创建广告单元了,点击Setup下面的Ad units,在出现的页面中点击Create application ad unit,如下图:
  
DSC0007.jpg
  
  在出现的页面中填入Ad unit name,并选择广告单元的大小,这里提供了两种尺寸,见下图:
  
DSC0008.jpg
  
                     添加完Ad unit name和Size后我们还要选择一下广告的类别,在类别选中我们只能选三个。如下图:
  

DSC0009.jpg
  添加Global ad exclusions。如果你不想看到哪个网站的广告,你可以在下面的对话框中填入相应的Url。不填写也没问题。
                     点击SAVE进行保存后将出现一个关于Ad unit的详细列表,在这个列表中点击Ad unit Name进行修改,也可以重新创建一个Ad unit。如下图:
  
DSC00010.jpg
  4)说明
           在开发过程中,如果你使用模拟器来查看刚刚申请的广告控件的话,会没有任何广告显示出血来,因为微软怕造成非法广告点击,而且微软的广告控件可以识别程序是否运行在模拟器上,所以在模拟器上广告控件是不会显示的,不过贴心的微软提供了三组测试数据,可以使用这些数据测试广告控件在Windows Phone 7中的实际效果。
           以下是三组测试数据的测试值,如下图:
  
DSC00011.jpg
  


  B)在XNA中使用Adcertising
        首先需要明确的一点是在Windows Phone for XNA中使用Adcertising与在Windows Phone for Silverlight中使用Adcertising是不同的,在SL中可以直接使用Adcertising控件进行控制,而在XNA中需要添加相关代码来实现,以下是微软提供的实例代码当然你也可以去下载加深理解!在自己添加的工作中,别忘记引用Microsoft.Advertising.Mobile.Xna.dll和Microsoft.Advertising.Mobile.Xna命名空间!



//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;
using Microsoft.Advertising.Mobile.Xna;
using System.Diagnostics;
using System.Device.Location;
namespace XnaGameWithAd
{
    ///
    /// This is the main type for your game
    ///
    public class Game1 : Microsoft.Xna.Framework.Game
    {
    
        private static readonly string ApplicationId = "test_client"; // 如果在实际使用中,需要换成您之前申请的ApplicationId
        private static readonly string AdUnitId = "TextAd"; //other test values: Image480_80, Image300_50, TextAd,在实际使用中换成您之前申请的AdUnitId
      
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        DrawableAd bannerAd; // bannerAd代表一个广告单元
        // We will use this to find the device location for better ad targeting.
        private GeoCoordinateWatcher gcw = null;
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            // Frame rate is 30 fps by default for Windows Phone.
            TargetElapsedTime = TimeSpan.FromTicks(333333);            
        }
        ///
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        ///
        protected override void Initialize()
        {
            // Initialize the AdGameComponent with your ApplicationId and add it to the game.
            AdGameComponent.Initialize(this, ApplicationId);
            Components.Add(AdGameComponent.Current);
            // Now create an actual ad for display.
            CreateAd();
            base.Initialize();
        }
        ///
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        ///
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            // TODO: use this.Content to load your game content here
        }
        ///
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        ///
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }
        ///
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        ///
        /// Provides a snapshot of timing values.
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            // TODO: Add your update logic here

            base.Update(gameTime);
        }
        ///
        /// This is called when the game should draw itself.
        ///
        /// Provides a snapshot of timing values.
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }
        ///
        /// Create a DrawableAd with desired properties.
        ///
        private void CreateAd()
        {
            // Create a banner ad for the game.
            int width = 480;
            int height = 80;
            int x = (GraphicsDevice.Viewport.Bounds.Width - width) / 2; // centered on the display
            int y = 5;
            bannerAd = AdGameComponent.Current.CreateAd(AdUnitId, new Rectangle(x, y, width, height), true);
            // Add handlers for events (optional).
            bannerAd.ErrorOccurred += new EventHandler(bannerAd_ErrorOccurred);
            bannerAd.AdRefreshed += new EventHandler(bannerAd_AdRefreshed);
            // Set some visual properties (optional).
            //bannerAd.BorderEnabled = true; // default is true
            //bannerAd.BorderColor = Color.White; // default is White
            //bannerAd.DropShadowEnabled = true; // default is true
            // Provide the location to the ad for better targeting (optional).
            // This is done by starting a GeoCoordinateWatcher and waiting for the location to be available.
            // The callback will set the location into the ad.
            // Note: The location may not be available in time for the first ad request.
            AdGameComponent.Current.Enabled = false;
            this.gcw = new GeoCoordinateWatcher();
            this.gcw.PositionChanged += new EventHandler(gcw_PositionChanged);
            this.gcw.StatusChanged += new EventHandler(gcw_StatusChanged);
            this.gcw.Start();
        }
        ///
        /// This is called whenever a new ad is received by the ad client.
        ///
        ///
        ///
        private void bannerAd_AdRefreshed(object sender, EventArgs e)
        {
            Debug.WriteLine("Ad received successfully");
        }
        ///
        /// This is called when an error occurs during the retrieval of an ad.
        ///
        ///
        /// Contains the Error that occurred.
        private void bannerAd_ErrorOccurred(object sender, Microsoft.Advertising.AdErrorEventArgs e)
        {
            Debug.WriteLine("Ad error: " + e.Error.Message);
        }
        private void gcw_PositionChanged(object sender, GeoPositionChangedEventArgs e)
        {
            // Stop the GeoCoordinateWatcher now that we have the device location.
            this.gcw.Stop();
            bannerAd.LocationLatitude = e.Position.Location.Latitude;
            bannerAd.LocationLongitude = e.Position.Location.Longitude;
            AdGameComponent.Current.Enabled = true;
            Debug.WriteLine("Device lat/long: " + e.Position.Location.Latitude + ", " + e.Position.Location.Longitude);
        }
        private void gcw_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
        {
            if (e.Status == GeoPositionStatus.Disabled || e.Status == GeoPositionStatus.NoData)
            {   
                // in the case that location services are not enabled or there is no data
                // enable ads anyway
                AdGameComponent.Current.Enabled = true;
                Debug.WriteLine("GeoCoordinateWatcher Status :" + e.Status);               
            }
        }
        ///
        /// Clean up the GeoCoordinateWatcher
        ///
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
            if (disposing)
            {
                if (this.gcw != null)
                {
                    this.gcw.Dispose();
                    this.gcw = null;
                }
            }
        }
    }
}
  
      让我们看一下运行后的效果,如下图:
  
DSC00012.jpg
  我顺手展示下自己开发的小游戏中加入的Adcertising,思路很简单就是在你游戏继承了Game的类中CreateAd()下,代码基本跟示例代码一致,但每个游戏的设计会有所不同,根据个人的设计自行调整下就可以了,如下图:
  
DSC00013.jpg

  
      OK,基本的流程大致就是这样,赶快行动吧!:)
  版权所有 DSC00014.png 欢迎转载
  

  

  

  

  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-64980-1-1.html 上篇帖子: Windows 8 Developer Preview 完美与 Windows 7 共存法安装指南 下篇帖子: 在Windows 7使用Connectify来创建wifi热点的详细过程
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表