目前通过Adobe AIR发布iOS应用的案例已经很多了. 随着AIR runtime及AIR SDK的不断升级,AIR App for iOS在iDevice运行流畅度大大提高.感谢Adobe带给大家这么好的技术和工具.
在苹果商店中, 可直接发布付费应用获得收益, 也可免费发放并通过广告得到分成. 但AIR不支持原生iAd广告组件.这时只能通过ANE(Air Native Extension)调用苹果原生API. 官方ANE插件站推荐了iOS iAd Native Extension for Adobe AIR插件. 最近无意中在Google Code找到iad-air-ios,重要的是, 它是免费的
下面通过Flash Builder 4.6介绍下使用方法.
1. 打开FB4.6, 新建ActionSript Mobile Project, 本例中使用iAdTest为项目名.去掉黑梅和安卓的选项, 只勾选iOS系统:
2. 前往iad-air-ios, 下载最新的插件 iAdPrefixed.zip 并解压.
3.打开iAdTest项目属性,选择ActionScript Build Path, 切换到Native Extensions, 选择第2步解压的ANE文件并添加到项目.
4. 敲入主程序代码:
package { import com.adobe.nativeExtensions.AdBanner; import com.adobe.nativeExtensions.AdBannerEvent; import com.adobe.nativeExtensions.AdBannerPosition; import flash.display.Sprite; import flash.display.Stage; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; public class iAdTest extends Sprite { public function iAdTest() { super(); this.addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler); } protected function addedToStageHandler(event:Event):void { this.removeEventListener(Event.ADDED_TO_STAGE, addedToStageHandler); stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; initAD(); } private function initAD():void { AdBanner.adView.startShowingAds(AdBannerPosition.TOP, false); AdBanner.adView.addEventListener(AdBannerEvent.AD_LOADED, adLoaded); AdBanner.adView.addEventListener(AdBannerEvent.AD_LOADING_FAILED, adFailed) AdBanner.adView.addEventListener(AdBannerEvent.USER_INTERACTION_STARTING, adStart); AdBanner.adView.addEventListener(AdBannerEvent.USER_INTERACTION_FINISHED, adFinished); } private function adLoaded(event:AdBannerEvent):void { trace("Ad Loaded"); AdBanner.adView.visible = true; trace("leaving: " + event.leaving); } private function adFailed(event:AdBannerEvent):void { trace("Loaded Failded: " + event.errorCode); AdBanner.adView.visible = false; } private function adStart(event:AdBannerEvent):void { trace("Starting"); trace(stage.orientation); } private function adFinished(event:AdBannerEvent):void { trace("Finished"); trace(stage.orientation); } } }
5.为配合从网络下载的证书, 要打开iAdTest-app.xml修改id:
<!– A universally unique application identifier. Must be unique across all AIR applications.
Using a reverse DNS-style name as the id is recommended. (Eg. com.example.ExampleApplication.) Required.–>
<id>com.gamevil.zenonia2</id>
6.发布程序
7. 如果没有意外情况发生, 等待数分钟便可发布完成.
连接iPhone(已越狱),将生成的iAdTest.ipa安装并运行,稍等片刻就可以看到左边的界面了.
运行截图:
程序源代码,证书(密码1234): 点击此处下载