I used
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
to get the launchOptions.
But it was not triggered, even if I added the UIApplicationDelegate protocol.
Welcome any comment
Be sure the File's Owner delegate outlet is connected to your App delegate class in the main nib file, unless you want to set it programmatically:
Which iOS version did you try? This works in iOS 3.0 and later.
I recall some odd behavior (this may or may not be true, but something to try) that if you ALSO implement the old method:
- (BOOL)applicationDidFinishLaunchingWithOptions:(UIApplication *)application
Then it will call that instead. Can you confirm you don't have that method?
Related
I use AppDelegate's method
-(BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
to import file from Mail application. After this method runs, my root ViewController - UITableViewController appears, but tableView doesn't reacts on reloadData method(I checked that data array was updated successfully).
Upd.: All delegates are set, tableView works OK, but contain old data.
Before I was using storyboards, all of my controllers were initialized in:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
I could init all the common objects (data managers, etc) before creating controllers, and pass them to controllers.
In my first storyboard project, I noticed that one of my controllers has its
- (void)viewDidLoad
//called before the app's
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
If I"m using storyboards and my controllers get loaded before the app finishes launching, where should I put my common objects init code to ensure that it gets called only once?
Thank you!
From the docs for application:didFinishLaunchingWithOptions:
...It is called after your application has been launched and its main
nib file has been loaded.
To prevent loading your storyboard before your initialization you can remove your main xib file or storyboard in the -Info.plist (for storyboard it is called Main storyboard file base name). Then you can create your storyboard manually when you need that.
Is there a way to run an action when the iPhone gets locked?
I simply want to run a little bit of code when the iPhone gets locked by the user. I'm looking for a solution that works without a jailbreaked iPhone.
https://stackoverflow.com/a/7888507/267892
May be you need to implement following methods in AppDelegate:
Tells the delegate that the application is now in the background.
- (void)applicationDidEnterBackground:(UIApplication *)application
Tells the delegate that the application has become active.
- (void)applicationDidBecomeActive:(UIApplication *)application
Tells the delegate that the application is about to become inactive.
- (void)applicationWillResignActive:(UIApplication *)application
See UIApplicationDelegate Protocol Reference for more info on these.
Take a look at UIApplicationDelegate Protocol Reference
especially applicationProtectedDataDidBecomeAvailable:
and applicationProtectedDataWillBecomeUnavailable:
I have a problem in adapting my iPhone App to Universal.
In my iPhone App, I have a tabBarController, with 5 tabs, each one with a tableView.
I need now to adapt it to iPad, so I'm implementing the following:
. A UISpliViewController, in which the rootViewController (left pane) is a tableView, to display in detailViewController (on the right side), each controller, corresponding to the tarBarController on the iPhone.
So, my problem is where do I assign the controllers to the splitView? In AppDelegate?
If I assign them in viewDidLoad on rootViewController, it don't work.
Anyone can help me? I'm stuck.
Thanks,
iChat: rui.lopes#me.com
create your splitview controller either in the xib or programmatically, then set the viewcontrollers
splitViewController.viewControllers = [NSArray arrayWithObjects:leftViewController, rightViewController, nil];
in either method
- (void)applicationDidBecomeActive:(UIApplication *)application or
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
In the AppDelegate's:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
method.
EDIT: Also see this SO post. Had bookmarked this when I started out.
UISplitViewController programmtically without nib/xib
I've done it.
I've added 5 ViewControllers to the AppDelegate, and the problem is solved.
Thanks,
Rui
I have an app that can be started up by clicking a link from outside the app. Before iOS 4 this worked fine. But now that you have to implement applicationWillEnterForeground, I'm having problems. The problem I have is going from this method to the handleOpenURL method.
I have no problems when didFinishLaunchingWithOptions is called because I handle the url there. But when my app goes into the background, then comes into the foreground, it appears that didFinishLaunchingWithOptions is not being called, or at least not completely. I say not completely because the splash screen comes up and you are taken to the home screen, but this logic only exists inside didFinishLaunchingWithOptions so I'm not sure how the splash page comes up without didFinishLaunchingWithOptions firing. However, the url logic does not fire when the app resumes, and this is also in didFinishLaunchingWithOptions.
I assume this is where I need to use applicationWillEnterForeground, but this method has not options parameter, so how do I get the url and pass it along to
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
All I'm really trying to do is have my app launch from a link after it becomes inactive the way it does when it first launches. I have not implemented applicationWillEnterForeground because I'm not sure what to do with it. All it really needs to do is handle the url.
in case you are still waiting for the answer,
just use the method
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
like you mentioned, this method will automatically be called when your application is called to handle a file ("open in ...")
however, this method is deprecated now, so use this instead
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation