unable to 'click' on adverts - objective-c

I have the following in my applicationDidFinishLaunching method:
ADBannerView* iAdView = [[ADBannerView alloc] initWithFrame:CGRectZero];
iAdView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
[[[CCDirector sharedDirector] openGLView] addSubview:iAdView];
Ads are visible but I can't click on any of them. What am I missing?

Check out these links, it seems you don't know about all the delegate methods and setup iAd actually needs.
http://developer.apple.com/library/ios/DOCUMENTATION/UserExperience/Reference/iAd_ReferenceCollection/_index.html
http://developer.apple.com/library/ios/documentation/userexperience/Reference/ADBannerView_Ref/Reference/Reference.html
http://developer.apple.com/library/ios/DOCUMENTATION/UserExperience/Conceptual/iAd_Guide/

If you see a blank white box and an unhandled error in your console ("no delegate or delegate does not implement didFailToReceiveWithError"), then the touch isn't working because no ad has been received yet. You'll need to implement the delegate method if you want to handle the receive error.
If you wait a while, an ad will probably appear. Then you'll be able to interact with it. If not, it's possible that you haven't signed up for the iAd program yet in iTunes Connect.

Related

After implementing facebook login replaceScene freezes

I have implemented facebook login according to https://developers.facebook.com/docs/facebook-login/ios/v2.1#login-apicalls
I have implemented this functionality in my AppDelegate. instead of - (IBAction)buttonTouched:(id)sender method I have same code under -(void)toggleFacebookOnOff; and accessing it from other classes via [(AppDelegate *)[[UIApplication sharedApplication] delegate] toggleFacebookOnOff];
When facebook session is NOT open and I call login method i.e my app redirects to facebook app and then back,calling method [[CCDirector sharedDirector] replaceScene:<#(CCScene *)#> withTransition:<#(CCTransition *)#>] Freezes whole application, no exceptions, no nothing.
Notes:
[[CCDirector sharedDirector] replaceScene:(CCScene *)]; is still functional.
I have noticed that actions are not performed anymore, e.g in different scene I have CCActionEaseInOut to scale sprite from 0.1f to 1.f and this sprite stays scaled.
problems are occurring after app redirects to FB app end then beck, no problem is occurring when I call FBSession openActiveSessionWithReadPermissions with parameter: allowLoginUI:NO.
Anyone has fix for this issue?

How to display iOS 6 Facebook alert view without first showing SLComposeViewController

In iOS 6, when you create an SLComposeViewController and show it with presentViewController and you have not called isAvailableForServiceType first, you will get the "No Facebook Account" alert view which gives the user an opportunity to set up their account in Settings.
Unfortunately it also shows the native Facebook posting dialog in the background as well.
I would like to have a cleaner experience than popping up two dialogs at the same time, so is there a way to only show the "No Facebook Account" dialog on its own after checking availability with isAvailableForServiceType?
Here's basically what I'd like to do:
// Check to see if the user has a Facebook account set up...
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *vc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler completionBlock = ^(SLComposeViewControllerResult result){
// do something when complete...
};
[vc setCompletionHandler:completionBlock];
[vc setInitialText:#"Intital text..."];
[self presentViewController:vc animated:YES completion:nil];
} else {
// No Facebook account configured yet,
// so show "No Facebook Account" alert view here.
}
Is this even possible, or will I just need to show a vanilla UIAlertView that tells the user to go to the Settings app and set up their Facebook Account?
BTW, I'm also guarding that block with a call that determines if this device even supports the use of SLComposeViewController, and if not, uses the Facebook SDK instead...
I wish it could be easy!! For now i was able to call the composeViewControllerForServiceType: method even without the account setup so it will show the alert with the settings button, hide the view but i couldn't be able to hide the keyboard!! Maybe you could find a way to reset the UITextFieldDelegate or whatevere esle to not show the keyboard...but I'm not sure! Let me know if you could figure it out!

Hiding the KeyWindow to cause a blank screenshot to be taken

I am trying to prevent the Apple implemmntation of taking a screenshot of the current screen contents when an app suspends into the background. I have found a piece of code that sort of works but it comes with a catch. What it does is that it clears the keywindow on the screen so when the snapshot is taken, it is of a blank screen. This is the code snippet for the functionality:
- (void)applicationWillResignActive:(UIApplication *)application
{
[ UIApplication sharedApplication ].keyWindow.hidden = YES;
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[ UIApplication sharedApplication ].keyWindow.hidden = YES;
}
The trouble with the above code is that when the app returns to the foreground, the view is gone as it has become hidden and i cannot unhide it with a simple
[ UIApplication sharedApplication ].keyWindow.hidden = NO;
in the applicationWillEnterForeground method of the app delegate. Does anyone know of a way to regain back the hidden view once i have hidden it in the background methods? Right now it is a black screen as the view has been hidden. What exactly happens when you hide a keywindow before going to background and then coming back. is that keywindow you hid before no longer the keywindow? Can anyone point me in the correct direction?
Thanks
Just made a demo project and was able to reproduce your issue. Indeed, the keyWindow property of the application is nil when applicationWillEnterForeground: is called.
Many times, your application's delegate will have a reference to its window - this is usually the Xcode default template for many applications. I was able to resolve the issue by calling
self.window.hidden = NO;
Instead of [UIApplication sharedApplication.keyWindow.hidden = NO;. Assuming that, like most of the templates, your application delegate has a window reference.
Another alternative that worked for me is to call [self.window makeKeyAndVisible];.
All this was done on the iOS 6 simulator.
Hope this helps!

Displaying Login View on app resume

What is the best way to display a view (in my case a login screen) on app resume. From looking around, I've been playing with the applicationDidBecomeActive event in my AppDelegate, but I cannot seem to get my head around how to properly display a view from here.
I've tried to grab the current window by using self.window and/or it's subviews, but from the AppDelegate self.window is nil.
So far this application seems to be wired up correctly, but I am baffled by two things.
A) why is self.window nil from within my AppDelegate's applicationDidBecomeActive event handler.
B) what is the correct/normal way of display a login view (or the like) on application resume.
Implement a custom UIViewController for all of your applications to inherent from. In this view controller implement logic in the viewWillAppear message to determine and show the login screen if necessary.
//CustomViewController.h
#interface CustomViewController : UIViewController
#end
//CustomerViewController.m
#implementation CustomViewController
-(void)viewWillAppear:(BOOL)animated{
if(login_required){
LoginViewController *loginView = [[LoginViewController alloc] initWithNibName:#"LoginView" bundle:nil];
[self presentModalViewController:loginView animated:false];
}
}
#end
Then, simply, in your login view controller make sure you call:
[self dismissModalViewControllerAnimated:false];
The benefits of this approach are two fold. Firstly, it's a very simple implementation. However, most compellingly, having a base class for an application's view controller presents the opportunity to extract common logic.
Jason,
I have worked on a security tutorial provided by Chris Lowe on raywenderlich.com that was intended to demonstrate how to use basic iOS security to lock the application.
The premise behind this tutorial though was that the application would prompt for login upon first launch and if application was resumed upon unlocking the device through the use of NSNoftificationCenter in viewDidLoad and subscribe the the notifications: deviceWillLock and deviceWillUnlock. All of this assumes the device is set to lock.
Basic iOS Security Tutorial Part 2 - This is the part that has the NSNotification registration.
Basic iOS Security Tutorial Part 1 - This is the first part of the tutorial for clarity.
I also ran into this problem and came across this question whilst researching a solution. I didn't want to create the intermediate super class for my views and I wasn't sure how it would work out with navigation controllers. I have come up with another solution that works well for me - so thought I would share it. It is based around the use of NSNotificationCenter .
In your app delegate create a property to hold a reference to the currently displayed view controller - say currentViewController.
Then in the applicationDidFinishLaunching method, register a block observer to update the currentViewController property like this:
[[NSNotificationCenter defaultCenter] addObserverForName:#"CurrentViewChanged"
object:nil
queue:nil
usingBlock:^(NSNotification *note)
{self.currentViewController = (UIViewController *)note.object;} ];
In your view controller implementations, update the viewDidAppear methods to notify the observer that a new view controller is being displayed by adding the following line
[[NSNotificationCenter defaultCenter] postNotificationName:#"CurrentViewChanged" object:self];
Finally, include code in the applicationDidBecomeActive method in your app delegate to force the modal display of your login screen.
UIStoryboard *mainStoryBoard = self.window.rootViewController.storyboard;
UnlockViewController *uvc = [mainStoryBoard instantiateViewControllerWithIdentifier:#"modalUnlockView"];
uvc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self.currentViewController presentViewController:uvc animated:YES completion:NULL];
A couple of additional items to note :-
You can disable the login screen display at anytime by posting a notification where the view controller passed is nil.
You only need to post the notification once for a navigation view controller at the top level. All view controllers in the navigation controller stack will be covered. I haven't checked, but I suspect the same is true for a tab view controller.
If you want to display the login screen the first time you enter the app after startup then include the following line in the applicationDidFinishLaunching method.
self.currentViewController = self.window.rootViewController;
I hope this is of some use.
Thanks

Get ADInterstitialAd to load more often on iPad: possible?

I'm testing my iAd on my iPad, and I can't seem to get my ADInterstitialAd to load very often.
It does run occasionally but most of the time the first method below is called
- (void)interstitialAd:(ADInterstitialAd *)interstitialAd didFailWithError:(NSError*)error{
NSLog(#"Ad Failed");
//[self cycleInterstitial];
}
However when I try to reload it upon failing.(see below method) It just fails over and over. I dont see why apple would let it just fail in a testing environment. I have read that the fill rate can be low, but it seems really low just for a test iPad app.
- (void)cycleInterstitial{
// Clean up the old interstitial...
interstitial.delegate = nil;
[interstitial release];
// and create a new interstitial. We set the delegate so that we can be notified of when
interstitial = [[ADInterstitialAd alloc] init];
interstitial.delegate = self;
}
Can anyone please advise? Thanks!
No, sorry. Apple is solely responsible for the fill rate of iAds, including interstitial iAds for iPad. As developers and users, we do not have any direct control over this.