iAd & Admob integration - iphone

I integrated iAd / Admob display code from the link from here: http://www.apptite.be/tutorial_mixing_ads.php
and had some weird results. On admob, my click through rate dropped 40%, but the number of impressions stayed the same. Its as if both ads are shown at the same time, with iAds on top of admob ads. Does anyone see problems with the code on that site that could possibly cause that?
Thank you in advance for your help.

Firstly we should download Admob Sdk from google.
That file is required In google AdMob API :-
GADAdSize.h
GADBannerView.h
GADBannerViewDelegate.h
GADInterstitial.h
GADInterstitial.h
GADRequest.h
GADRequestError.h
libGoogleAdMobAds
#import <UIKit/UIKit.h>
#import "GADBannerViewDelegate.h"
#class GADBannerView, GADRequest;
#interface BannerExampleViewController : UIViewController
<GADBannerViewDelegate> {
GADBannerView *adBanner_;
}
#property (nonatomic, retain) GADBannerView *adBanner;
- (GADRequest *)createRequest;
#end
#import "BannerViewController.h"
#import "GADBannerView.h"
#import "GADRequest.h"
#implementation BannerExampleViewController
#synthesize adBanner = adBanner_;
#pragma mark init/dealloc
// Implement viewDidLoad to do additional setup after loading the view,
// typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
CGPoint origin = CGPointMake(0.0,
self.view.frame.size.height -
CGSizeFromGADAdSize(kGADAdSizeBanner).height);
self.adBanner = [[[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner
origin:origin]
autorelease];
self.adBanner.adUnitID = AdMob key;
self.adBanner.delegate = self;
[self.adBanner setRootViewController:self];
[self.view addSubview:self.adBanner];
[self.adBanner loadRequest:[self createRequest]];
}
- (void)dealloc {
adBanner_.delegate = nil;
[adBanner_ release];
[super dealloc];
}
#pragma mark GADRequest generation
- (GADRequest *)createRequest {
GADRequest *request = [GADRequest request];
request.testing = YES;
return request;
}
#pragma mark GADBannerViewDelegate impl
- (void)adViewDidReceiveAd:(GADBannerView *)adView {
NSLog(#"Received ad successfully");
}
- (void)adView:(GADBannerView *)view
didFailToReceiveAdWithError:(GADRequestError *)error {
NSLog(#"Failed to receive ad with error: %#", [error localizedFailureReason]);
}
#end

Hmm, so I'm looking at the code that says:
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSLog(#"iAdBanner failed");
// Only request adMob when iAd did fail
[self adMobRequest];
And on Apple's site, it says that "Even after an error is sent to your delegate, the banner view continues to try to download new advertisements. Thus, implementing both of these delegate methods allows your application to display the banner only when advertisements are loaded." (link)
I'm guessing that what is happening is that if iAd fails, you're displaying an AdMob ad, but then iAd is also retrying as well and so if it fails again, it is requesting another AdMob ad despite the fact that one may already be getting shown?

Related

Thread 1 signal sigabrt error

When I launch my app the build succeeds, but when almost right in the beginning it crashes and highlights the following:
return UIApplicationMain(argc, argv, nil, NSStringFromClass([yes_or_no_AppDelegate class]));
and says:
Thread 1: signal SIGABRT
int main(int argc, char *argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([yes_or_no_AppDelegate class]));
}
}
Error message in console:
[GADObjectPrivate changeState:]: unrecognized selector sent to instance
I found out that this is the part that is causing the error. If I delete it I'm able to launch the app.
[self.bannerView setRootViewController:self];
But when i launch the app i don't receive a banner and receive error message in console:
Must set the rootViewController property of GADBannerView before calling loadRequest:
This is my .h file and the code I've used is from googles demo app on banners:
#class GADBannerView, GADRequest;
#interface MainViewController : UIViewController <GADBannerViewDelegate> {
GADBannerView *adBanner_;
}
#property(nonatomic, strong) GADBannerView *adBanner;
and my .m file also from google demo app:
#synthesize adBanner = adBanner_;
#pragma mark init/dealloc
// Implement viewDidLoad to do additional setup after loading the view,
// typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
// Initialize the banner at the bottom of the screen.
CGPoint origin = CGPointMake(0.0,
self.view.frame.size.height -
CGSizeFromGADAdSize(kGADAdSizeBanner).height);
// Use predefined GADAdSize constants to define the GADBannerView.
self.adBanner = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner
origin:origin]
;
// Note: Edit SampleConstants.h to provide a definition for kSampleAdUnitID
// before compiling.
self.adBanner.adUnitID = kSampleAdUnitID;
self.adBanner.delegate = self;
[self.bannerView setRootViewController:self];
[self.view addSubview:self.adBanner];
self.adBanner.center =
CGPointMake(self.view.center.x, self.adBanner.center.y);
[self.adBanner loadRequest:[self createRequest]];
}
- (void)dealloc {
adBanner_.delegate = nil;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
#pragma mark GADRequest generation
// Here we're creating a simple GADRequest and whitelisting the application
// for test ads. You should request test ads during development to avoid
// generating invalid impressions and clicks.
- (GADRequest *)createRequest {
GADRequest *request = [GADRequest request];
// Make the request for a test ad. Put in an identifier for the simulator as
// well as any devices you want to receive test ads.
request.testDevices =
[NSArray arrayWithObjects:
// TODO: Add your device/simulator test identifiers here. They are
// printed to the console when the app is launched.
nil];
return request;
}
#pragma mark GADBannerViewDelegate impl
// We've received an ad successfully.
- (void)adViewDidReceiveAd:(GADBannerView *)adView {
NSLog(#"Received ad successfully");
}
- (void)adView:(GADBannerView *)view
didFailToReceiveAdWithError:(GADRequestError *)error {
NSLog(#"Failed to receive ad with error: %#", [error localizedFailureReason]);
}
Here's your problem:
[GADObjectPrivate changeState:]: unrecognized selector sent to instance
Did you type the method name correctly? This means the method you are calling does not exist. More specifically the GADObjectPrivate class does not contain this method.
The crash when calling changeState: has been asked before. See this question:
AdMob crashes with [GADObjectPrivate changeState:]: unrecognized selector

iAd doesn't hide when it fails to load?

This seems like the dumbest question ever, but after wading through all of Apple's documentation and the useless online tutorials, I still can't figure out how to properly implement iAds into my application. So, my app starts off in a table view controller, and I have an iAd object underneath the navigation bar and above the table.
Now, in my code: (I also have the iAd framework added)
#import <UIKit/UIKit.h>
#import <iAd/iAd.h>
#interface MasterTableViewController : UITableViewController <ADBannerViewDelegate>
{
IBOutlet ADBannerView *iAd;
}
#property(nonatomic, readonly, getter=isBannerLoaded) BOOL bannerLoaded;
#end
then in the .m file
#import "MasterTableViewController.h"
#interface MasterTableViewController ()
#end
#implementation MasterTableViewController
#synthesize bannerLoaded;
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
if (!willLeave)
{
// nothing in this case thanks to ARC
}
return YES;
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
iAd.hidden = NO;
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
iAd.hidden = YES;
}
- (void)viewDidLoad
{
[super viewDidLoad];
for (int i = 0; i > 0; i++)
{
if (bannerLoaded)
{
iAd.hidden = NO;
}
else
{
iAd.hidden = YES;
}
}
}
Now, the problem is, when I test the app without internet connection the iAd does not load (obviously) BUT it also does not hide. So, at the top of the screen I'm left with a big white rectangle. Otherwise, the ad works fine when a connection is available. Does anyone have any ideas? Also - I just added the endless loops to see if they made a difference, those were completely on purpose lol.
I'm assuming you have added your ADBannerView via the Storyboard as I can't see where you initialise the banner position.
In storyboard, set the initial location just off screen.
In "bannerViewDidLoadAd", animate the banner into view.
In "bannerView: didFailToReceiveAdWithError:", animate the banner out of view.
There is a good example here https://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/iAd_Guide/WorkingwithBannerViews/WorkingwithBannerViews.html
Hope this helps. I have just implemented this but don't have access to my code at the moment.
It does bring up some errors in the simulator but works fine on a device.
I have tested this on iOS6 and works ok even if an iAd is displayed then the user loses the connection (so it looks like "bannerView: didFailToReceiveAdWithError:" is being called for me).
You have a property bannerLoaded for saving the state of your Ad, which is good.
At the very first, in your viewDidLoad method, iAd can't be loaded, so you have to set your property accordingly : self.bannerLoaded = NO;
Then, when you receive / fail to receive your ad, you need to update this property.
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!self.bannerLoaded) {
iAd.hidden = NO;
self.bannerLoaded = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerLoaded) {
iAd.hidden = YES;
self.bannerLoaded = NO;
}
}

signal SIGABRT when testing on device, it works on simulator. Easy code

I'm not experienced in programming.
I was trying to do an easy iOS app (just to try some tutorials) that works as a "sendmail"
Easy interface with just 1 button that when pressed, it opens the MFMailComposeViewController window.
That's the code.
ViewController.h
#import <UIKit/UIKit.h>
#import <MessageUI/MFMailComposeViewController.h>
#import <MessageUI/MessageUI.h>
#interface ViewController : UIViewController <MFMailComposeViewControllerDelegate>
-(IBAction)showPicker:(id)sender;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
-(IBAction)showPicker:(id)sender
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
NSArray *toRecipients = [NSArray arrayWithObject:#"example#example.com"];
[picker setToRecipients:toRecipients];
[picker setSubject:#"TEST SUBJECT"];
[self presentViewController:picker animated:YES completion:nil];
}
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
On the iPhone and iPad simulator it works like a charm.
But when testing it on the device it crashes giving signal SIGABRT and showing as evidence that part of main.m:
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
with a "Thread 1 - Signal SIGABRT" near.
Any tip?
Thanks to everyone in advance.
Two things to try:
Clean the files <SHIFT+CMD+K>
Uninstall the file from your device and try with the cleaned one
Right at the beginning of showPicker: add this :
if [MFMailComposeViewController canSendMail]
{
// Your code
}
else
NSLog(#"No mail account configured on device or not supported");

Why is my app crashing when I try to play a sound using the Finch library for iPhone SDK?

I followed the instructions in the read me file exactly, but for some reason, in my app, every time I hit the UIButton corresponding to the code to play the sound "[soundA play]; the app just crashes without any detailed error description except for lldb. I'm using Finch because it plays the audio using OpenAL, and I need to use OpenAL for the type of app I'm making because AVAudioPlayer or System Sounds are not usable for what I'm making. Here is the code that I am using.
Main file:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
soundFactory = [[FIFactory alloc] init];
engine = [soundFactory buildSoundEngine];
[engine activateAudioSessionWithCategory:AVAudioSessionCategoryPlayback];
[engine openAudioDevice];
soundA = [soundFactory loadSoundNamed:#"1.caf" maxPolyphony:16 error:NULL];
soundB = [soundFactory loadSoundNamed:#"2.caf" maxPolyphony:16 error:NULL];
soundC = [soundFactory loadSoundNamed:#"3.caf" maxPolyphony:16 error:NULL];
soundD = [soundFactory loadSoundNamed:#"4.caf" maxPolyphony:16 error:NULL];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
- (IBAction) PlaySoundA {[soundA play];}
- (IBAction) PlaySoundB {[soundB play];}
- (IBAction) PlaySoundC {[soundC play];}
- (IBAction) PlaySoundD {[soundD play];}
#end
Header file:
#import <UIKit/UIKit.h>
#import "FISoundEngine.h"
#import "FIFactory.h"
#import "FISound.h"
#interface ViewController : UIViewController {
FIFactory* soundFactory;
FISoundEngine* engine;
FISound* soundA;
FISound* soundB;
FISound* soundC;
FISound* soundD;
}
#end
Any help would be appreciated! Thanks!
Most likely the sound player cannot find your sound file. try right clicking on the audio file and selecting view in finder. make sure the file is actually in your project directory and not

how to implement AdBannerview and ADBannerview delegate

I am having trouble implementing ADBannerView and its delegate protocol.
I implemented the following code in my view class (also made the view conform to the ADBannerViewDelegate protocol):
//add iAds
ADBannerView *adView = [[ADBannerView alloc] initWithFrame: CGRectMake(0, 318, 320, 50)];
adView.requiredContentSizeIdentifiers = [NSSet setWithObjects: ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil];
adView.delegate = self;
//adView.delegate = ADBannerViewDelegate;
[self.view addSubview: adView];
then I created a class for the ADBannerViewDelegate, with the following .m
//
// ADBannerViewDelegate.m
//
#import "ADBannerViewDelegate.h"
#implementation ADBannerViewDelegate
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
NSLog(#"bannerview did not receive any banner due to %#", error);}
- (void)bannerViewActionDidFinish:(ADBannerView *)banner{NSLog(#"bannerview was selected");}
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave{return willLeave;}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {NSLog(#"banner was loaded");}
#end
the banners are eventually presented but the console keep throwing the following type of errors:
2011-02-27 15:00:54.108 app[31639:207] ADBannerView: Unhandled error (no delegate or delegate does not implement didFailToReceiveAdWithError:): Error Domain=ADErrorDomain Code=5 "The operation couldn’t be completed. Banner view is visible but does not have content" UserInfo=0x6356a40 {ADInternalErrorCode=5, NSLocalizedFailureReason=Banner view is visible but does not have content}
and the delegate functions are not doing anything , so no NSLog at all. Obviously not catching the errors.
I am stumped. I guess I am missing something in the linkage of the Adbanner view calls in the view and the delegate. Not sure how to do it or what is wrong.
Any help? Thanks in advance.
Jason
The reason why is you told the AdBannerView that you are its delegate but you never put it in your implementation file. Your implementation file should look like this (notice the line with #implmentation):
//
// ADBannerViewDelegate.m
//
#import "ADBannerViewDelegate.h"
#implementation ADBannerViewDelegate<ADBannerViewDelegate>
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
NSLog(#"bannerview did not receive any banner due to %#", error);}
- (void)bannerViewActionDidFinish:(ADBannerView *)banner{NSLog(#"bannerview was selected");}
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave{return willLeave;}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {NSLog(#"banner was loaded");}
#end
And also you shouldn't name your class ADBannerViewDelegate. Your class should be a delegate (respond to it) to ADBannerView but not be named after it.
i successfully integrated iAds in my app using this tutorial:
http://www.raywenderlich.com/1371/how-to-integrate-iad-into-your-iphone-app
might help you too.
You don't try to implement a class named ADBannerViewDelegate, you put those methods in the implementation for your view class.
(If you actually named your view class "ADBannerViewDelegate", don't. It's confusing.)
For me it was the target and the device, I ran it on the 4.3 simulator and my ipad 2 but the app was for iphone 5.1, when I changed the target all went swimmingly
you can Use this link its very helpful
http://codewithchris.com/iad-tutorial/