Titanium无法在iOS模拟器上显示admob

时间:2012-06-17 07:37:07

标签: ios admob titanium-modules

我正在努力让Admob与Titanium iOS App一起使用。

首先,我下载了Ti.admob模块并将其集成到我的应用程序中。 我可以在Titanium控制台上看到我的应用程序找到了Ti.Admob模块,但模拟器屏幕上没有显示任何内容。

这是我在ApplicationWindow.js中的代码

Titanium.Admob = require('ti.admob');
function ApplicationWindow(title) {
var currentwindow = Ti.UI.createWindow({
    title:title,
    backgroundColor:'red'
});

setAds(currentwindow);  
return currentwindow;
};
module.exports = ApplicationWindow;

function setAds(currentwin)
{
var ad; 
ad = Titanium.Admob.createView({
    top: 50, 
    left: 0,
    width: 320, 
    height: 50,
    publisherId: '<MY API KEY>',
    adBackgroundColor: 'black',
    testing: true,
    dateOfBirth: new Date(1981, 1, 1, 1, 1, 1),
    gender: 'female',
    keywords: 'test'
});

currentwin.add(ad);

ad.addEventListener('didReceiveAd', function() {
    alert('Did receive ad!');
});
ad.addEventListener('didFailToReceiveAd', function() {
    alert('Failed to receive ad!');
});
ad.addEventListener('willPresentScreen', function() {
    alert('Presenting screen!');
});
ad.addEventListener('willDismissScreen', function() {
    alert('Dismissing screen!');
});
ad.addEventListener('didDismissScreen', function() {
    alert('Dismissed screen!');
});
ad.addEventListener('willLeaveApplication', function() {
    alert('Leaving the app!');
});

}

这是我的Titanium控制台。

[INFO] One moment, building ...
[INFO] Detected third-party module: ti.admob/1.0
[INFO] Detected third-party module: ti.admob/1.0
[INFO] Titanium SDK version: 2.0.1 (04/12/12 16:33 999c68a)
[INFO] iPhone Device family: universal
[INFO] iPhone SDK version: 5.0
[INFO] iPhone simulated device: iphone
[INFO] Performing full rebuild. This will take a little bit. Hold tight...
[INFO] Performing clean build
[INFO] Compiling localization files
[INFO] Launching application in Simulator
[INFO] Launched application in Simulator (21.40 seconds)
[INFO] Application started
[INFO] testAdmob/1.0 (2.0.1.GA2.999c68a)
[INFO] AdMob module loaded

1 个答案:

答案 0 :(得分:0)

您没有在此代码中使用admob模块。你必须像这样改变setAds函数(注意Admob.createView而不是Titanium.Admob.createView:

function setAds(currentwin) {
var Admob = require('ti.admob');
var ad;
ad = Admob.createView({
    top : 50, ........