applicationWillEnterForeground handleOpenURL problem - iphone

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

Related

Detect app opening?

I have a Tab bar app with 3 view controllers and I use "viewWillAppear" to detect which view is opend.
When I close the app, it still works "in the background" and when I open the app again "viewWillAppear" is not detecting this opening.
Is there any other option to detect this opening? Thanks
You can observe the UIApplicationWillEnterForegroundNotification or implement applicationWillEnterForeground: in your app delegate.
Firstly, You should see the necessary delegation method in UIApplicationDelegate
When you close application that currently open, It will call this method:
- (void)applicationDidEnterBackground:(UIApplication *)application
After the application has been closed but still in dock, you open them again. In the transition state before entering the application, It will call this method:
- (void)applicationWillEnterForeground:(UIApplication *)application
When the application completely presented on previous state before you closed them. It finally call thid method:
- (void)applicationDidBecomeActive:(UIApplication *)application
If you would like to do something in viewWillAppear you should implement in applicationDidBecomeActive to send some message to your current view or other to do what do you want to do after application became actived.
When your app is resumed from the background, it will receive the applicationWillEnterForground: method. It'll get the applicationDidEnterBackground: when it is suspended too.
- (void)applicationWillEnterForeground:(UIApplication *)application {
NSLog(#"app will enter foreground");
[viewController refresh:NULL];
}
i think this will work.
write this in your app delegate

fbDidLogin or fbDidNotLogin not called

I am trying to integrate facebook login in my existing app. I have the openURL and handleOpenURL methods in AppDelegate.m, but i initialize facebook object in one of the view Controller on click of a button. so my fbDidLogin method is in the viewController, which never gets called. Neither is the fbDidNotLogin is called.
Is it something wrong I am doing?
I had the same problem and it was because i hadn´t set the URL types in the info.plist like it says on the tutorial http://developers.facebook.com/docs/mobile/ios/build/#register
And I have forgotten to implement the only method in the AppDelegate:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [[FacebookService sharedInstance].facebook handleOpenURL:url];
}
FacebookService - is my wrapper singletone class, that contains instance og facebook
the error was the same

iOS lock event?

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:

How can I know if my apps come from background or are already in foreground

I want to handle APNs differently whether my application come from background or is already in the foreground. Do you know what methods could help me ?
These are the messages that handle the notification about a changing application state.
– application:didFinishLaunchingWithOptions:
– applicationDidBecomeActive:
– applicationWillResignActive:
– applicationDidEnterBackground:
– applicationWillEnterForeground:
– applicationWillTerminate:
– applicationDidFinishLaunching:
You must implement the one's you need in the designated Delegate! Take a look at the "Task" section of the following link for further assistance, especially the "Monitoring application state changes" part ;-)
Apple's UIApplicationDelegate Protocol Reference
- (void)applicationDidBecomeActive:(UIApplication *)application
It is a method which is executed when app comes to foreground from background. So you can write your code here under the above method about whatever you want to do when app comes to foreground from being in background.
(void)applicationWillResignActive:(UIApplication *)application;
(void)applicationDidEnterBackground:(UIApplication *)application;
(void)applicationWillEnterForeground:(UIApplication *)application;
(void)applicationDidBecomeActive:(UIApplication *)application ;
Please have a look at these methods written in delegate.m file
You must implement the application:didReceiveLocalNotification: method. This will be called for both cases. You can differentiate between the cases by checking the applicationState property of [UIApplication sharedApplication]: if it's UIApplicationStateInactive then the app was in background, and if it's UIApplicationStateActive then the app was in foreground.

Discovering if a component is being displayed (of if it's in background), is it possible?

I need to run a method everytime the user switch the screen or return to the application (after a call, or pressing the "Home Button" and returning to the app, for example).
Is there any way to recognize this, like an event or method that is always executed when this happens?
Thank you guys in advance.
Implement those 2 methods in the UIApplicationDelegate :
- (void)applicationDidEnterBackground:(UIApplication *)application
- (void)applicationWillEnterForeground:(UIApplication *)application