0

I am trying to get Admob to work with Titanium iOS App.

First of all I downloaded the Ti.admob module and integrated it to my app. I could see on the Titanium console while it's building that my app found Ti.Admob module, but nothing was shown on the simulator screen.

This is my code in 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!');
});

}

And this is my Titanium console.

[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
Aing
  • 116
  • 10

1 Answers1

0

you did not use the admob module in this code. you have to alter the setAds function like this (notice Admob.createView and not Titanium.Admob.createView:

function setAds(currentwin) {
var Admob = require('ti.admob');
var ad;
ad = Admob.createView({
    top : 50, ........
hini
  • 240
  • 1
  • 11
  • Sorry, I had a line Titanium.Admob = require('ti.admob'); at the beginning of the file, but it didn't work out. I edited my original post to have admob module line. – Aing Jun 23 '12 at 05:07
  • Admob = require('ti.admob'), and not Titanium.Admob I tested your code and it works fine when the code is updated as indicated – hini Jun 23 '12 at 08:44
  • I tested the code with Titanium.Admob and it worked fine. when did you create your admob account ? if it was a new account then expect such weird problems as it happened with me, it will work fine few days later. first my code didn't show ads, I ran it few days later without change and it worked fine. – hini Jun 23 '12 at 08:51