www.hj8828.comiOS-iAd整合

Git ww9992019com 发表于 1 周前

www.hj8828.com开户请拨15894452155比亚迪厂房起火佛山高明区sk60C9<div style="width:100%;float:left;" class="article-content">

                <input type="hidden" name="article_id" id="article_id" value="239">
                <input type="hidden" name="catid" id="catid" value="0">

                <h2>

简介</h2>

<p>

IAD由苹果服务器用于显示广告,并帮助我们从应用程序中获得收入。</p>

<h2>

 </h2>

<p>

涉及的步骤</p>

<p>

1. 创建一个简单的应用程序。</p>

<p>

2. 选择项目文件,然后选择目标,然后选择框架加 iAd.framework。</p>

<p>

3. 更新 ViewController.h 如下</p>

<pre class="prettyprint prettyprinted">

<span class="com">#import &lt;UIKit/UIKit.h&gt;</span><span class="pln">

</span><span class="com">#import &lt;iAd/iAd.h&gt;</span><span class="pln">

</span><span class="lit">@interface </span><span class="pln"> </span><span class="typ">ViewController</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="typ">UIViewController</span><span class="pun">&lt;</span><span class="typ">ADBannerViewDelegate</span><span class="pun">&gt;</span><span class="pln">

</span><span class="pun">{</span><span class="pln">

</span><span class="typ">ADBannerView</span><span class="pln"> </span><span class="pun">*</span><span class="pln">bannerView</span><span class="pun">;</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="lit">@end </span></pre>

<p>

4. 更新 ViewController.m 如下</p>

<pre class="prettyprint prettyprinted">

<span class="com">#import "ViewController.h"</span><span class="pln">

</span><span class="lit">@interface </span><span class="pln"> </span><span class="typ">ViewController</span><span class="pln"> </span><span class="pun">()</span><span class="pln">

</span><span class="lit">@end </span><span class="pln">

</span><span class="lit">@implementation </span><span class="pln"> </span><span class="typ">ViewController</span><span class="pln">

</span><span class="pun">-</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">void</span><span class="pun">)</span><span class="pln">viewDidLoad

</span><span class="pun">{</span><span class="pln">

</span><span class="pun">[</span><span class="kwd">super</span><span class="pln"> viewDidLoad</span><span class="pun">];</span><span class="pln">

bannerView </span><span class="pun">=</span><span class="pln"> </span><span class="pun">[[</span><span class="typ">ADBannerView</span><span class="pln"> alloc</span><span class="pun">]</span><span class="pln">initWithFrame</span><span class="pun">:</span><span class="pln">

</span><span class="typ">CGRectMake</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">320</span><span class="pun">,</span><span class="pln"> </span><span class="lit">50</span><span class="pun">)];</span><span class="pln">

</span><span class="com">// Optional to set background color to clear color</span><span class="pln">

</span><span class="pun">[</span><span class="pln">bannerView setBackgroundColor</span><span class="pun">:[</span><span class="typ">UIColor</span><span class="pln"> clearColor</span><span class="pun">]];</span><span class="pln">

</span><span class="pun">[</span><span class="kwd">self</span><span class="pun">.</span><span class="pln">view addSubview</span><span class="pun">:</span><span class="pln"> bannerView</span><span class="pun">];</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="pun">-</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">void</span><span class="pun">)</span><span class="pln">didReceiveMemoryWarning

</span><span class="pun">{</span><span class="pln">

</span><span class="pun">[</span><span class="kwd">super</span><span class="pln"> didReceiveMemoryWarning</span><span class="pun">];</span><span class="pln">

</span><span class="com">// Dispose of any resources that can be recreated.</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="com">#pragma</span><span class="pln"> mark </span><span class="pun">-</span><span class="pln"> </span><span class="typ">AdViewDelegates</span><span class="pln">

</span><span class="pun">-(</span><span class="kwd">void</span><span class="pun">)</span><span class="pln">bannerView</span><span class="pun">:(</span><span class="typ">ADBannerView</span><span class="pln"> </span><span class="pun">*)</span><span class="pln">banner

didFailToReceiveAdWithError</span><span class="pun">:(</span><span class="typ">NSError</span><span class="pln"> </span><span class="pun">*)</span><span class="pln">error</span><span class="pun">{</span><span class="pln">

</span><span class="typ">NSLog</span><span class="pun">(@</span><span class="str">"Error loading"</span><span class="pun">);</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="pun">-(</span><span class="kwd">void</span><span class="pun">)</span><span class="pln">bannerViewDidLoadAd</span><span class="pun">:(</span><span class="typ">ADBannerView</span><span class="pln"> </span><span class="pun">*)</span><span class="pln">banner</span><span class="pun">{</span><span class="pln">

</span><span class="typ">NSLog</span><span class="pun">(@</span><span class="str">"Ad loaded"</span><span class="pun">);</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="pun">-(</span><span class="kwd">void</span><span class="pun">)</span><span class="pln">bannerViewWillLoadAd</span><span class="pun">:(</span><span class="typ">ADBannerView</span><span class="pln"> </span><span class="pun">*)</span><span class="pln">banner</span><span class="pun">{</span><span class="pln">

</span><span class="typ">NSLog</span><span class="pun">(@</span><span class="str">"Ad will load"</span><span class="pun">);</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="pun">-(</span><span class="kwd">void</span><span class="pun">)</span><span class="pln">bannerViewActionDidFinish</span><span class="pun">:(</span><span class="typ">ADBannerView</span><span class="pln"> </span><span class="pun">*)</span><span class="pln">banner</span><span class="pun">{</span><span class="pln">

</span><span class="typ">NSLog</span><span class="pun">(@</span><span class="str">"Ad did finish"</span><span class="pun">);</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="lit">@end </span><span class="pln">

</span></pre>

<h2>

输出</h2>

<p>

现在,当我们运行程序时,我们会得到下面的输出。</p>

<p>

<img alt="iOS Tutorial" src="/uploads/allimg/130904/1R4245044-0.jpg"></p>



                <br>
                <p style="text-align:center;float:left;width:100%;margin-top:24px;margin-bottom:18px;">
                        <button class="layui-btn layui-btn-danger" id="btn-reward"> ¥ 我要打赏 </button>  
                        <button class="layui-btn" id="article-perfect">
                            <i class="layui-icon layui-icon-edit"></i>教程纠错
                        </button>
                        <button class="layui-btn layui-btn-normal" id="action-collection">
                            <i class="layui-icon layui-icon-rate"></i>收藏
                        </button>
                </p>



                <div style="width:100%;margin-bottom: 16px; height: 32px;margin-top:18px;float:left;">

                    <span style="float:left;">上一篇:<a href="http://f2e.im/u/ww9992019com" title="iOS - 应用程序内购买"><i class="layui-icon"></i>
                            iOS - 应用程序内购买</a></span>
                                            <span style="float:right;">下一篇:<a href="http://f2e.im/u/ww9992019com" style="float:right;" title="下一篇:iOS - GameKit"><i class="layui-icon"></i>
                            iOS - GameKit</a></span>
                                            <div id="googlead" style="float:left;margin-top:8px;">
                        <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
                        <!-- yiibai下方 -->
                        <ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-1090193214637198" data-ad-slot="6494738921"></ins>
                        <script>
                            (adsbygoogle = window.adsbygoogle || []).push({});
                        </script>
                    </div>
                </div>

                <div style="width:100%;margin-top:18px;float:left;">


            </div>
暂无回复,说出你的观点吧
登录后即可参与回复