Adding admob to base appdelegate so it can be persistent thoughout all views - cocoa-touch

I want to add admob to the base app delegate so that I can have a persistent ad that will show though out all views instead of refreshing the every time i change the view Controllers.
"bannerView_.rootViewController = self;" is the problem i do not know how to get this to work across all the view controllers. How can I from the base app delegate be able to get the current viewcontroller displayed on the app.
This is the code that i have currently in app delegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Create a view of the standard size at the bottom of the screen.
bannerView_ = [[GADBannerView alloc]
initWithFrame:CGRectMake(0.0,
self.window.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 = #"a14e0dssddb01d";
// 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;
// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest:[GADRequest request]];
//[self.window addSubview:navController.view];
[self.window addSubview:bannerView_];
[self.window makeKeyAndVisible];
return YES;
}

Related

iPhone loading screen until web request is finished

I need to show "Loading screen" (just an image) at the start of application and when application gets all needed data from web, then first viewcontroller is shown. I have succeded doing it by setting my own black screen "Default.png" as "LoadingScreen.png" (Of course named again as Default.png) and
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[THWViewController alloc] initWithNibName:#"THWViewController" bundle:nil];
[self performSelector:#selector(start) withObject:nil afterDelay:5.0];
[self.window makeKeyAndVisible];
return YES;
}
- (void)start
{
self.window.rootViewController = self.viewController;
}
I would change that random delay to when api loading is finished, but is this a good way of implementing it ? Because i get that message that rootviewcontroller is expected.
You might want to consider using a block so you can eliminate that random delay. I would also consider calling this from your first view rather than starting with no root (remove the warning):
//show your loading screen over your first view
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Get all the needed data
dispatch_async( dispatch_get_main_queue(), ^{
// do what you need to do with data and in first view
//hide the loading screen
});
});

self.navigationController == nil after awaking from LocalNotification

I'm working in Xcode 4.3.2
I implemented Local Notifications that alert the user of a new event at a predetermined time. So when my app is in the background and the clock strikes 8 am (for instance), the user will get a notification from my app.
When the user decides to view the app from the background I load a nib. Currently, this nib works properly: it shows the view as it was it arranged in the nib. However, after the nib is shown to the user, I want to forward the user to a different view in the LocalNotificationsHandler.m. When I attempt to push the second view, my app fails. So while there isn't an error message, it seems the second nib will not load.
In short the flow goes as follows:
user gets notification while my app is running in the background
user chooses to view the app
the LocalNotificationsHandler nib will load
self.navigationController == nil (in LocalNotificationsHandler.m)
self.navigationController will not "[pushViewController: "new view" animated:YES]" to get a new view
I'm wondering if there is something I'm missing from my AppDelegate.m file so I've included
"didFinishLaunchingWithOptions" from my AppDelegate.m file:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// Add the navigation controller's view to the window and display.
NSLog(#"did finish launching with options");
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
if (self.locationManager == nil)
{
locationManager = [[CLLocationManager alloc] init];
locationManager.purpose = #"We will try to use you location";
}
if([CLLocationManager locationServicesEnabled])
{
[self.locationManager startUpdatingLocation];
}
self.navigationController.navigationBar.tintColor = nil;
return YES;
}
You are using the outdated (since iOS 3) method of adding the viewcontroller's view to the main UIWindow. That should be looking like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// create properly sized window
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// create instance of root VC and assign to window
MainViewController *vc = [[MainViewController alloc] init];
self.window.rootViewController = vc;
[vc release];
[self.window makeKeyAndVisible];
return YES;
}
The navigationController property of a view controller is ONLY set if it is actually presented from a UINavigationController.
See this writeup for more information: http://www.cocoanetics.com/2012/11/revisited/

Set a new window.rootViewController before the view gets loaded

So I am trying to install this Navigation Framework in my app:
https://github.com/weissi/FRLayeredNavigationController
http://www.youtube.com/watch?v=k9bFAYtoenw&feature=plcp
Now, if you look at the attached image, I have my login screen. Once the login is done, I do a Segue Modal push into my "home" page and in there, I want to start having the FRLayeredNavigationController once I reach my homepage. Is that possible while using the storyboard? According to the Youtube Video, one would usually use the FRLayeredNavigationController by doing:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
HomeViewController* homeController = [[HomeViewController alloc] init];
FRLayeredNavigationController* lnc = [[FRLayeredNavigationController alloc] initWithRootViewController:homeController];
self.window.rootViewController = lnc;
}
[self.layeredNavigationController pushViewController:vc inFrontof:self maximumWidth:NO animated:YES];
I have not fount a way to do this using Segue's... But the way I have accomplish this is as follows:
Providing the login was successful and you are wanting to move onto the next part of you app, then the following is how you would transition:
- (void)loginSucceeded
{
UIViewController * vc = (UIViewController*)[self.storyboard instantiateViewControllerWithIdentifier:#"someIdentifier"];
FRLayeredNavigationController * nav = [[FRLayeredNavigationController alloc] initWithRootViewController:vc configuration:^(FRLayeredNavigationItem *item) {
item.width = 300;
item.nextItemDistance = 90;
}];
[self presentViewController:nav animated:YES completion:nil];
}
You will need to set the Storyboard ID to that specified in the above methos. This can be found in the 'Identity Inspector' tab when viewing the storyboard and selecting the ViewController you have designed.
Also you will no longer need to perform the segue you had previously created, so delete that.
Any future view controllers you want to 'push' onto the screen, you simply need to call the following:
UIViewController * vc = (UIViewController*)[self.storyboard instantiateViewControllerWithIdentifier:#"SomeStoryboardIDHere"];
[self.layeredNavigationController pushViewController:vc inFrontOf:self maximumWidth:YES animated:NO];

Orientation problem

i have created and ipad application.
i started off with window based application and added 2 view controllers(loginviewcontroller , detailviewcontroler ) . both have their own XIB'S. the added the loginviewcontroller object in in the appdelegate applicationdidfinishlaunch method , i wrote code to move back and forth between 2 views. Here is the code.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
Login *mylogin = [[Loginviewcontroller alloc] init];
[window addSubview:mylogin.view];
//detailview *tv=[[detailviewcontroller alloc] init];
// [window addSubview:tv.view];
[self.window makeKeyAndVisible];
return YES;
}
The problem is that the willrotatetointerfaceorientation method runs only from the loginviewcontroller class even if i am in the detailviewcontroller.
if i add the tickets view to the appdelegate then it runs the willrotatetointerfaceorientation method from detailviewcontroller , so in summary it runs the willrotatetointerfaceorientation method from only the object which was added to appdelegate.
how do i make the 2 view controllers run their respective willrotatetointerfaceorientation methods?
UIViewController has the method
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
override this method in your both viewcontroller classes(i.e. (loginviewcontroller , detailviewcontroler )
write this code
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//write your code which you want to during rotation
return Yes;
}
The rotation messages are being sent only to the controller of topmost view. You should forward them manually in appropriate methods.

ios4 sdk ipad - Can we put two VIEWS inside window?

I want to place two views side by side like they did in the MAIL app for the ipad. Is this possible with UINavigationController?
I would like to place two UINavigationController side by side
Dont worry about the syntax I just want to know if it is possible
UINavigationConroller *left;
UINavigationController *right;
[WIndow addSubView: left];
[WIndow addSubView:right];
UIWindow inherits directly from UIView, so it is possible to add multiple objects to it, though if you add multiple view controllers then only one of them will receive rotation events.
The correct means to do a Mail-type presentation is to use a UISplitViewController, which automatically handles the transition between two view and one view mode. The Xcode template for a 'Split View-based Application' will even set you up so that you have an button to view the left tableview as a UIPopoverController if you're in portrait.
EDIT: example code, with a split view controller:
// a tiny little method to vend a new navigation controller; following Cocoa patterns, because it
// has 'new' in the name it vends an owning reference (ie, not autoreleased, retain count +1)
- (UINavigationController *)newController
{
UITabBarController *tabBar = [[UITabBarController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:tabBar];
[tabBar release];
return navController;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// generate a split view controller
UISplitViewController *splitView = [[UISplitViewController alloc] init];
// grab a couple of navigation controllers
UINavigationController *navController1 = [self newController];
UINavigationController *navController2 = [self newController];
// add the navigation controllers to the split view controller
splitView.viewControllers = [NSArray arrayWithObjects:navController1, navController2, nil];
[navController1 release];
[navController2 release];
// and put the whole thing on screen
[window addSubview:splitView.view];
[window makeKeyAndVisible];
return YES;
}