How to implement AdMob in Phonegap - iphone

I have a phonegap application and im trying to implementing Admob.
I'm using phonegap version 1.4.1 and I am using this site as my reference : http://iphone.keyvisuals.com/iphonedev/implementing-admob-ads-in-a-phonegap-project-for-ios-no-plugins-required/
My code is as follows:
(void)webViewDidFinishLoad:(UIWebView *)theWebView
{
bannerView_ = [[GADBannerView alloc]init];
[bannerView_ setDelegate:self];
[bannerView_ setFrame:CGRectMake(0, 0, 320, 50)];
// Specify the ad's "unit identifier." This is your AdMob Publisher ID.
bannerView_.adUnitID = MY_BANNER_UNIT_ID;
// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
bannerView_.rootViewController = self.viewController;
[self.viewController.view addSubview:bannerView_];
// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest:[GADRequest request]];
// only valid if AdGap.plist specifies a protocol to handle
if(self.invokeString)
{
// this is passed before the deviceready event is fired, so you can access it in js when you receive deviceready
NSString* jsString = [NSString stringWithFormat:#"var invokeString = \"%#\";", self.invokeString];
[theWebView stringByEvaluatingJavaScriptFromString:jsString];
}
return [ super webViewDidFinishLoad:theWebView ];
}
Everything is fine, but when I am running the application, no ads are being displayed.

Please make sure that your "theWebView" object finishes its webload. And that the bannerView_ is a registered property of your object.
Also, I hope you just put in "MY_BANNER_UNIT_ID" to hide your banner unit id.
Check up with your admob settings if the banner unit id is correct.
And finally, please use a iphone proxy like Charles or similar to validate that the call goes out as it should.

Phonegap has been upgraded. It support new features. just add this code in your config.
<gap:plugin name="com.admob.plugin" version="1.0.0" source="plugins.cordova.io"/>

Related

phonegap - webViewDidFinishLoad not getting called

I am using Phonegap2.1. I have the webViewDidFinishLoad method in my AppDelegate.m file. It used to get called by its own in previous phonegap versions. Now, it does not get called at all. Do I need to assign the delegate somewhere?
- (void)webViewDidFinishLoad:(UIWebView *)theWebView
{
if(self.invokeString)
{
// this is passed before the deviceready event is fired, so you can access it in js when you receive deviceready
NSString* jsString = [NSString stringWithFormat:#"var invokeString = \"%#\";", self.invokeString];
[theWebView stringByEvaluatingJavaScriptFromString:jsString];
}
// Black base color for background matches the native apps
theWebView.backgroundColor = [UIColor blackColor];
return [ self.viewController webViewDidFinishLoad:theWebView ];
}
When you upgrade to 2.1.0, it is recommended that you comment out all that section because it is deprecated. The code you supplied does not actually help you in any way when using cordova 2.1.0 so if you comment it out, your app should work just fine.
http://iphonedevlog.wordpress.com/2012/09/24/phonegap-2-1-0-in-mac-os-x-mountain-lion-10-8-from-download-to-ios-app-store/
#pragma UIWebDelegate implementation
/*
- (void) webViewDidFinishLoad:(UIWebView*) theWebView
{
// only valid if ___PROJECTNAME__-Info.plist specifies a protocol to handle
if (self.invokeString)
{
// this is passed before the deviceready event is fired, so you can access it in js when you receive deviceready
NSLog(#"DEPRECATED: window.invokeString - use the window.handleOpenURL(url) function instead, which is always called when the app is launched through a custom scheme url.");
NSString* jsString = [NSString stringWithFormat:#"var invokeString = \"%#\";", self.invokeString];
[theWebView stringByEvaluatingJavaScriptFromString:jsString];
}
// Black base color for background matches the native apps
theWebView.backgroundColor = [UIColor blackColor];
return [super webViewDidFinishLoad:theWebView];
}*/
Leaving this section uncommented gives this warning:
Classes/MainViewController.m:133:11: 'invokeString' is deprecated
Classes/MainViewController.m:137:86: 'invokeString' is deprecated
Your app will run fine only it is not ideal to be releasing products that have warnings.
Unless if you deliberately did not put your code for the whole world to see
[CB-853] Deprecate window.invokeString - use window.handleOpenURL(url) instead
http://mail-archives.apache.org/mod_mbox/incubator-callback-commits/201207.mbox/%3C20120716205424.998B414A2D#tyr.zones.apache.org%3E

Why is my AdMob code leaking in my iphone app?

I have included AdMob in my iphone app. I have the following code in my viewDidLoad method:
bannerView_ = [[GADBannerView alloc]
initWithFrame:CGRectMake(0.0,
0.0,
320,
50)];
// Specify the ad's "unit identifier." This is your AdMob Publisher ID.
bannerView_.adUnitID = ADMOB_BANNER_UNIT_ID;
// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
// Initiate a generic request to load it with an ad.
GADRequest *r = [[GADRequest alloc] init];
r.testing = YES;
[bannerView_ loadRequest:r];
[r release];
This leaks. When I comment out the second last line ( [bannerView_ loadRequest:r]; ), the leak disappears. The only thing I changed in this code from the example provided by Google was to introduce the variable r so I could put AdMob in testing mode. In the code supplied by Google, bannerView_ is released by viewDidUnload. I looked for the loadRequest method but all I found was a definition in the GADBannerView.h file. As far as I can tell, there is no GADBannerView.m file, which seems weird in itself. Anyway, any tips would be much appreciated.
Thanks,
John
Why don't you use this AdMediator - it is very simple to configure and you don't have to worry about AdMob and iAds (if you want to use it) :
will swap in AdMob ads if no iAds are
available.
Are you releasing bannerView_ in your dealloc method or somewhere else appropriate ?
Instead of:
GADRequest *r = [[GADRequest alloc] init];
You could try:
GADRequest *r = [GADRequest request];

iPhone - AdMob not appearing. Using sample code

I'm trying to add AdMob to my app.
I followed the instructions from the example from here: http://code.google.com/mobile/ads/docs/ios/fundamentals.html
with the subtle difference that I created a method and I'm calling it from the viewDidLoad
The problem is that nothing is appearing, not even an empty frame. I also tried deleting everything except the main view from Interface Builder to make sure that is not behind something but nothing is appearing.
What can I've doing wrong?
Here's my method code:
- (void)showBanner {
// Create a view of the standard size at the bottom of the screen.
bannerView_ = [[GADBannerView alloc]
initWithFrame:CGRectMake(0.0,
self.view.frame.size.height -
GAD_SIZE_320x50.height,
GAD_SIZE_320x50.width,
GAD_SIZE_320x50.height)];
// Specify the ad's "unit identifier." This is your AdMob Publisher ID.
bannerView_.adUnitID = #"heresthestringofmyadmobid";
// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
[self.view bringSubviewToFront:bannerView_];
// Initiate a generic request to load it with an ad.
GADRequest *request = [GADRequest request];
request.testDevices = [NSArray arrayWithObjects:
GAD_SIMULATOR_ID, // Simulator
#"heresthestringofmyphone", // Test iPhone 3Gs 4.3.1
nil];
[bannerView_ loadRequest:request];
}
I also tried harcoding the CGFrame with 0, 0, 320, 50 to make it appear on top but nothing happened either
Chompas,
You could not be getting a ad because of a low fill rate or other issue. To check if this is the issue, try enabling testMode so you will always get an ad.
You can do that with something like this:
GADRequest *request = [[GADRequest alloc] init];
request.testing = YES;
[bannerView_ loadRequest:request];
-David
.testing is now deprecated. You can instead use this:
#ifdef DEBUG
GADRequest *request = [GADRequest request];
request.testDevices = [NSArray arrayWithObjects:
GAD_SIMULATOR_ID,
#"YOUR_DEVICE_IDENTIFIER",
nil];
[bannerView_ loadRequest:request];
#else
[bannerView_ loadRequest:[GADRequest request]];
#endif
If you want test ads support in your real device and not just in the emulator, YOUR_DEVICE_IDENTIFIER should be replaced by your device identifier, which you can find while your device is connected under xCode menu > Window > Organizer > Devices. It's a long hex number.
I think you missed to set the delegate for processing events like ad recieved, ad failed, etc. I made the same mistake. [adView setDelegate: )]

AdMob not showing ads in iOS simulator

I am trying to use AdMob on an app (built for iOS 4.0)
I've added the sample code available in the tutorial http://code.google.com/mobile/ads/docs/ios/fundamentals.html which is the following (I've changed the adUnitID):
// Create a view of the standard size at the bottom of the screen.
bannerView_ = [[GADBannerView alloc]
initWithFrame:CGRectMake(0.0,
self.view.frame.size.height -
GAD_SIZE_320x50.height,
GAD_SIZE_320x50.width,
GAD_SIZE_320x50.height)];
// Specify the ad's "unit identifier." This is your AdMob Publisher ID.
bannerView_.adUnitID = #"XYZ";
// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
[self.view bringSubviewToFront:bannerView_];
GADRequest * request = [GADRequest request];
// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest:request];
Doing this nothing happens, no ad is shown and the number of requests in my AdMob app page increase erratically (i.e.: I can't seem to notice a pattern), but the most important is no ad is shown.
If I add the following code:
GADRequest * request = [GADRequest request];
request.testDevices = [NSArray arrayWithObjects:
GAD_SIMULATOR_ID, // Simulator
nil];
// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest:request];
I get the "Success! You are now ready to travel through the App Galaxy" default banner, but only this one.
So my questions are:
Aren't the sample code enough to show ads? Why I never see an ad with the sample code?
As far as I understood, requests mean the number of times my app asked for an ad to be shown. I also understood that not every request is replied with an ad (otherwise the fill rate would be 100%), but still, I NEVER saw an ad, what am I doing wrong?
Thanks in advance.
GADBannerView *bannerView = [[GADBannerView alloc]
initWithFrame:CGRectMake(0.0,
self.view.frame.size.height -
GAD_SIZE_320x50.height,
GAD_SIZE_320x50.width,
GAD_SIZE_320x50.height)];//Set Position
bannerView.adUnitID = #"12331255421245";//Call your id
// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
bannerView.rootViewController = self;
[self.view addSubview:bannerView];//Your attempt to add bannerview
// Initiate a generic request to load it with an ad.
[bannerView loadRequest:[GADRequest request]];
I set all above methods. Ad banner looks properly in Device but not showing ad in Simulator.
I set device Id as GAD_SIMULATOR_ID.but it doesnt work. Its delegate methods are not being called. !!
Try it in the device. Apps in simulator don't show Admob ads.

Limit providers while integrating Gigya in iPhone?

I am integrating Gigya in my iphone app. Now it provides 17 providers for access, I want to limit it to just 9 providers. How can I do that?
Has any one integrated it for iPhone? It loads a web view which displays 17 providers in a grouped table format, see here.
To set Facebook and Twitter you can use following code.
GSDictionary *pParams5 = [[GSDictionary new] autorelease];
[pParams5 putStringValue:#"facebook,twitter" forKey:#"enabledProviders"];
[gsAPI showAddConnectionsUI:pParams5 delegate:self context:nil];
GSAPI *gsAPI // declare this
gsAPI = [[GSAPI alloc] initWithAPIKey:<API-KEY> viewController:self]; // i kept this in viewDidload
// add this code to have facebook and twitter on provider list
GSDictionary *pParams5 = [[GSDictionary new] autorelease];
[pParams5 putStringValue:#"facebook,twitter" forKey:#"enabledProviders"];
[gsAPI showAddConnectionsUI:pParams5 delegate:self context:nil];
//this method called when login fails
-(void)gsLoginUIDidFail:(int)errorCode errorMessage:(NSString*)errorMessage context:(id)context{ }
// this method called on successful login
- (void) gsLoginUIDidLogin:(NSString*)provider user:(GSDictionary*)user context:(id)context {}
Check whether you have valid API