Anything to active iAd? - ios

I have finished my first application. I put iAd banners on it. And active iAd from iTunnes Connect.
I learned to add iAd from this tutorial. http://www.youtube.com/watch?v=fP2ijcXbCz4
Do I need to add something else to my code? Will ads be shown automatically?
#interface TOCGMainViewController () <ADBannerViewDelegate>
#property (strong, nonatomic) IBOutlet ADBannerView *iAdBanner;
#end
#implementation TOCGMainViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if ([[ UIScreen mainScreen ] bounds ].size.height == 568 ) {
nibNameOrNil = [NSString stringWithFormat:#"%#_568", nibNameOrNil ?: #"TOCGMainViewController"];
}
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
}
if ([ADBannerView instancesRespondToSelector:#selector(initWithAdType:)]) {
self.iAdBanner = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
} else {
self.iAdBanner = [[ADBannerView alloc] init];
}
return self;
}
...
...
...
#pragma mark - ADBannerViewDelegate
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
NSUserDefaults *saveApp = [NSUserDefaults standardUserDefaults];
bool saved = [saveApp boolForKey:k_Save];
if (!saved) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
} else {
banner.hidden = YES;
[banner removeFromSuperview];
banner = nil;
banner.delegate = nil;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:0];
[UIView commitAnimations];
}
#end

To test your iAd code, you can simply run the app on the simulator or your device. If you set up everything correctly, you should see a demo banner that indicates this. This will be replaced with the actual ads when the app goes into the store.

Related

Shared iAd banner bannerViewDidLoadAd not being called

I am using the following code to setup a shared iAd banner.
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_adView = [[ADBannerView alloc]init];
}
ViewController.m
-(void) viewWillAppear:(BOOL)animated {
AppDelegate *appdelegate = (AppDelegate *)[[UIApplication sharedApplication ]delegate];
_adView = [appdelegate adView];
_adView.delegate = self;
self.canDisplayBannerAds = true;
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:0];
[UIView commitAnimations];
}
bannerView:didFailToReceiveAdWithError is getting called as expected but bannerViewDidLoadAd is never called. I am trying to move some buttons up on the screen when the iAd banner loads.
Your shared banner does not appear to be just one ADBannerView. It looks like you've set multiple #property's for your ADBannerView in your AppDelegate.h and your ViewController.h. Also, self.canDisplayBannerAds = true is creating an entirely new and different ADBannerView for you. self.canDisplayBannerAds = true can be used for a no hassle way of implementing iAds in your application. This will create a ADBannerView for you and show or hide the ADBannerView depending on whether it receives an ad or not from the iAd network. You will want to remove this from your viewDidLoad if you plan to implement a ADBannerView yourself.
Here is what your implementation of your shared ADBannerView should look like:
AppDelegate.h
#import <UIKit/UIKit.h>
#import iAd;
#interface AppDelegate : UIResponder <UIApplicationDelegate> {
}
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) ADBannerView *iAdView;
#end
AppDelegate.m
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_iAdView = [[ADBannerView alloc]init];
return YES;
}
ViewController.h
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#interface ViewController : UIViewController <ADBannerViewDelegate>
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController {
AppDelegate *appDelegate;
}
-(void)viewDidLoad {
[super viewDidLoad];
appDelegate = (AppDelegate *)[[UIApplication sharedApplication ]delegate];
appDelegate.iAdView.delegate = self;
appDelegate.iAdView.frame = CGRectMake(0, 0, appDelegate.iAdView.frame.size.width, appDelegate.iAdView.frame.size.height);
[self.view addSubview:appDelegate.iAdView];
// You created another adView property in your ViewController.h?
//_adView = [appdelegate adView];
//_adView.delegate = self;
// This will actually create ANOTHER ADBannerView
// Do not use when creating your own ADBannerView
//self.canDisplayBannerAds = true;
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
NSLog(#"iAd LOADED");
[UIView beginAnimations:nil context:NULL];
appDelegate.iAdView.alpha = 1.0;
[UIView commitAnimations];
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
NSLog(#"iAd FAILED");
[UIView beginAnimations:nil context:NULL];
appDelegate.iAdView.alpha = 0.0;
[UIView commitAnimations];
}

iAd Banner won't load correctly

I followed a youtube tutorial on how to implement shared iads banner in my app. I have 10 VC so this is why i choosed the shared iads via delegate. Whenever I launch the app (On device or simulator) the ad doesn't appear on the first view controller. If i switch to the 2nd VC, it will load and show correctly. Then if i decide to go to the 3rd VC or back to the 1st VC, the banner will be white and no ads will load (even if i wait or go to any other VC).
Maybe the tutorial i watched wasn't correctly written, i don't know to be honest. Here's the code used:
AppDelegate.h
#property (strong, nonatomic) ADBannerView *UIiAD;
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
_UIiAD = [[ADBannerView alloc] init];
return YES;
}
ViewController.h
#property (strong, nonatomic) ADBannerView *UIiAD;
ViewController.m
- (AppDelegate *) appdelegate {
return (AppDelegate *)[[UIApplication sharedApplication] delegate];
}
-(void) viewWillAppear:(BOOL)animated{
_UIiAD = [[self appdelegate] UIiAD];
_UIiAD.delegate = self;
if ((int)[[UIScreen mainScreen] bounds].size.height == 568)
{
[_UIiAD setFrame:CGRectMake(0,518,320,50)];
}
if ((int)[[UIScreen mainScreen] bounds].size.height == 480)
{
[_UIiAD setFrame:CGRectMake(0,430,320,50)];
}
if ((int)[[UIScreen mainScreen] bounds].size.height == 667)
{
[_UIiAD setFrame:CGRectMake(0,600,320,50)];
}
if ((int)[[UIScreen mainScreen] bounds].size.height == 736)
{
[_UIiAD setFrame:CGRectMake(0,660,320,50)];
}
[self.view addSubview:_UIiAD];
}
-(void) viewWillDisappear:(BOOL)animated{
[_UIiAD removeFromSuperview];
_UIiAD.delegate = nil;
_UIiAD = nil;
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
NSLog(#"ads loaded");
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0];
[_UIiAD setAlpha:1];
[UIView commitAnimations];
self.fullscreen = [[RevMobAds session] fullscreen];
self.fullscreen.delegate = self;
[self.fullscreen loadAd];
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
NSLog(#"ads not loaded");
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0];
[_UIiAD setAlpha:0];
[UIView commitAnimations];
}
Conclusion
I tried adding a delay in the ViewWillAppear method but it did not work.
I placed the banner in the storyboard and made sure it was on 0 alpha.
No other answer on SO helped me so hopefully someone will be able to resolve this issue. Thanks!
To conclude my comments,
use storyboard auto layout to position the banner or use a placeholder to get the position of the later banner.
Remove the animations and replace them with .hidden=true and =false.
Set the adBanner to hidden in storyboard or at the point of your initialization.

My successfulRequestDidReturnObject method does not work when I login

I'm working on a sales application. created a registration and login system that works through Restkit. In my view the login and registration system is working. I check the console and second what I see everything went right. The User to appear in the database. My problem is that I try to use a method so that if the User log in correctly it is redirected to a view that for now has only a single label. However my console returns this error and the application is broken.
2015-02-26 17:19:37.164 MeuJavendi[6778:89059] I restkit:RKLog.m:49 RestKit logging initialized...
2015-02-26 17:19:53.992 MeuJavendi[6778:89059] I restkit.network:RKObjectRequestOperation.m:150 POST 'http://localhost:3000/users/sign_in.json'
2015-02-26 17:19:54.243 MeuJavendi[6778:89163] I restkit.network:RKObjectRequestOperation.m:222 POST 'http://localhost:3000/users/sign_in.json' (200 OK / 1 objects) [request=0.2465s mapping=0.0040s total=0.2701s]
2015-02-26 17:19:54.252 MeuJavendi[6778:89059] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard (<UIStoryboard: 0x7fe3e060db40>) doesn't contain a view controller with identifier 'AdsTableViewController''
*** First throw call stack:
The method I use to cause the action is this:
- (void)successfulRequestDidReturnObject:(NSObject *)object {
[[AppDelegate sharedDelegate] setCurrentUser:(User *)object];
[self.loadingIndicatorView stopAnimating];
AdsTableViewController *categoriesVC = [[UIStoryboard storyboardWithName:#"Ad" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:#"AdsTableViewController"];
[[[AppDelegate sharedDelegate] menuViewControlller] setPaneViewController:[[UINavigationController alloc] initWithRootViewController:categoriesVC]
animated:NO
completion:nil];
[self dismissViewControllerAnimated:YES completion:nil];
}
however my storyboard is configured for the right table view
This is the login of the complete code:
#import "LoginViewController.h"
#import "AppDelegate.h"
#import "JVWebService.h"
#import "AdsTableViewController.h"
#interface LoginViewController () <JVWebServiceDelegate>
#property (strong, nonatomic) IBOutlet UIButton *signInButton;
#property (strong, nonatomic) IBOutlet UIButton *forgotPasswordButton;
- (IBAction)signIn:(id)sender;
#end
#implementation LoginViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.emailTextField.delegate = self;
self.passwordTextField.delegate = self;
// [self setupFonts];
}
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
if ([self shouldEnableScrollViewOnIphone4S]) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.view cache:YES];
self.view.frame = CGRectMake(0, -60, self.view.frame.size.width, self.view.frame.size.height + 60);
[UIView commitAnimations];
}
}
-(void)textFieldDidEndEditing:(UITextField *)textField
{
if ([self shouldEnableScrollViewOnIphone4S]) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.view cache:YES];
self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 60);
[UIView commitAnimations];
}
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
return [textField resignFirstResponder];
}
- (void)requestDidFailWithError:(NSError *)error {
[JVUtils showMessage:error.localizedDescription withTitle:#"Erro"];
[[AppDelegate sharedDelegate] setCurrentUser:nil];
[self.loadingIndicatorView stopAnimating];
}
#pragma mark - Actions
- (IBAction)signIn:(id)sender {
if (!(self.emailTextField.text.length > 0)) {
[JVUtils showMessage:#"O campo e-mail não pode ficar em branco" withTitle:#"Opa!"];
[self.emailTextField becomeFirstResponder];
} else if (!(self.passwordTextField.text.length > 0)) {
[JVUtils showMessage:#"O campo senha não pode ficar em branco" withTitle:#"Opa!"];
[self.passwordTextField becomeFirstResponder];
} else {
[self.loadingIndicatorView startAnimating];
[[JVWebService sharedService] setServiceDelegate:self];
[[JVWebService sharedService] getUserForEmail:self.emailTextField.text andPassword:self.passwordTextField.text];
}
}
- (void)successfulRequestDidReturnObject:(NSObject *)object {
[[AppDelegate sharedDelegate] setCurrentUser:(User *)object];
[self.loadingIndicatorView stopAnimating];
AdsTableViewController *categoriesVC = [[UIStoryboard storyboardWithName:#"Ad" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:#"AdsTableViewController"];
[[[AppDelegate sharedDelegate] menuViewControlller] setPaneViewController:[[UINavigationController alloc] initWithRootViewController:categoriesVC]
animated:NO
completion:nil];
[self dismissViewControllerAnimated:YES completion:nil];
}
#end

Shared iAD banner but only on certain views

I have correctly implemented a shared iAd banner in the appDelegate and in certain views(which are adbanner delegates) it appears correctly. How ever in the views where I dont show the banner (so they are not adbanner delegates) when the appdelegate fails to retrieve a Banner since there is no current delegate and no current didFailToRecieveAdWithError method the console shows an error saying that efectively there is no method to recieve the error. Do i need to make the appDelegate also the AdBannerDelegate and put those methods inside?
In appDelegate:
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
// Override point for customization after application launch.
_UIiAD = [[ADBannerView alloc]init];
return YES;
}
in ViewController where I want a Banner:
- (CrystalAppDelegate *)appDelegate
{
return (CrystalAppDelegate *)[[UIApplication sharedApplication]delegate];
}
- (void)viewWillAppear:(BOOL)animated
{
_UIiAD = [[self appDelegate] UIiAD];
_UIiAD.delegate = self;
[_UIiAD setFrame:CGRectMake(0, 518, 320, 50)];
[self.view addSubview:_UIiAD];
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
NSLog(#"Banner did Load");
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[_UIiAD setAlpha:1];
[UIView commitAnimations];
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSLog(#"Banner did not Load");
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[_UIiAD setAlpha:0];
[UIView commitAnimations];
}
-(void)viewWillDisappear:(BOOL)animated
{
_UIiAD.delegate = nil;
_UIiAD = nil;
[_UIiAD removeFromSuperview];
}
Problem is when i am in a view that doesnt have a banner i dont have these methods so when the appDelegate doesnt retrieve a iAdBanner there is no method to revieve the error.

Could not instantiate class named ADBannerView

i am trying to inset an iad banner at the bottom of my app but keep getting errors after following tutorials.
code as follows.
#interface DMKHomeViewController (UIViewcontroller ) <ADBannerViewDelegate>{
}
#end
#implementation DMKHomeViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
}
- (void)bannerView:(ADBannerView *)
banner didFailToReceiveAdWithError:(NSError *)error
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:0];
[UIView commitAnimations];
}
i keep getting the following error
* Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named ADBannerView'
* First throw call stack:
Please make sure that you have added the "iAd.framework"...
To do this go to the "App. Target", "General" and scroll down until you see "Linked Frameworks and Libraries". Hit "+" and select the iAd framework. See screen captures below...
You have not created object of AdBannerview..
First, create object for banner view and set delegate for it.
-(void)ViewDidLoad
{
[self createBannerView];
}
- (void)createBannerView {
Class cls = NSClassFromString(#"ADBannerView");
if (cls) {
ADBannerView *adView = [[cls alloc] initWithFrame:CGRectZero];
// Set the current size based on device orientation
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
adView.delegate = self;
adView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleRightMargin;
// Set initial frame to be offscreen
CGRect bannerFrame =adView.frame;
bannerFrame.origin.y = self.view.frame.size.height;
adView.frame = bannerFrame;
self.bannerView = adView;
[self.view addSubview:adView];
[adView release];
}
}

Resources