終於經過了一個多月的抗戰,apple終於讓我把「DR.神仙道」「神仙我知道」上線了!
我一直以為是圖片的關係,卻原來是中文名稱的關係……
既然上線了,雖然只是我自己的小小練習,就順便來練習一下在ios app中怎麼放廣告吧~
Titanium很好心的幫我們準備了一個module:ti.admob,所以基本上,只是要記錄一下怎麼使用module來快速完成我們的需求!
- 下載最新module檔(目前是1.2)
- 解壓縮到/Library/Application Support/Titanium
- 打開專案的tiapp.xml把module掛上去:
<modules> <module version="1.2">ti.admob</module> </modules>
- 在想要放廣告的頁面加入
var Admob = require('ti.admob'); var ad; win.add(ad = Admob.createView({ bottom: 0, left: 0, width: 320, height: 50, publisherId: '<<YOUR PUBLISHER ID HERE>>', // You can get your own at http: //www.admob.com/ adBackgroundColor: 'black', testing: true, dateOfBirth: new Date(1985, 10, 1, 12, 1, 1), gender: 'male', keywords: '' })); tableView.addEventListener("touchstart", hideAD, false); tableView.addEventListener("scroll", hideAD, false); tableView.addEventListener("scrollEnd", showAD, false); win.addEventListener('focus',showAD); win.addEventListener('blur',hideAD); var ad_hide = Titanium.UI.createAnimation(); ad_hide.opacity = 0; ad_hide.duration = 100; var ad_show = Titanium.UI.createAnimation(); ad_show.opacity = 1; ad_show.duration = 1000; function hideAD(event) { ad.animate(ad_hide); } function showAD(event) { setTimeout( function(){ ad.animate(ad_show);},3000); }
當然,publisherId必須自己到admob申請!
就在「網站與應用程式」標籤裡,按下「管理設定」後,在網站url下可以找到「發佈商 ID」就是了。