I would like to show a userID/password view after the app is backgrounded for security purposes.
How should I implement it? Should I be using - (void)applicationDidEnterBackground:(UIApplication *)application?
I don't know about the security reasons but as I tested in both
- (void)applicationWillResignActive:(UIApplication *)application and
- (void)applicationDidEnterBackground:(UIApplication *)application
None of these can show UIComponent during application is have been resigned. May be local notification can help you with this but these too wouldn't be able to do exactly what you want.
Related
is - (void)applicationDidEnterBackground:(UIApplication *)application capable of making calculations every day at 10AM, even when app is closed complitly (killed with task manager).
Sorry for stupid question but I don't want to start making something pointless. :)
Sort of. You can implement background fetching for your app in this method
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
However, you can't just implement the method. You have to be sure to enable background fetching for your application. Background fetching
Note that you can choose one of two options
1: Have the iOS schedule the fetch for you based on when the user usually opens your app
2: Request a time interval between fetches. Not guaranteed to execute when you want though, just a request.
Could any help in creating a Unity3D App which could request some data from some webservice (let say every 5 mins) and send a local notification while the game app is running in the background.
You can use the AppController class that the Unity player creates. You need to respond to some of these messages:
- (void)applicationWillEnterForeground:(UIApplication *)application
- (void)applicationDidBecomeActive:(UIApplication *)application
- (void)applicationDidEnterBackground:(UIApplication *)application
These are called when the application goes from the background to active and vice-versa. If you want to communicate with unity, you can pass some info with:
UnitySendMessage("GameObjectName1", "InBackground", "Message to send");
If you send the message in (void)applicationDidEnterBackground:(UIApplication *)application
, the method InBackground() will be called. You can have coroutine in that method with is called in every fixed time. This is a theory. Try to implement it.
I am developing an iOS application where need to do some stuff when I have Internet connection and other, when I haven't. If I haven't at some point I will show a message to the user to give me internet and come back. The question it is how to detect the following situation:
the user press the Home button twice, goes to multitasking , Settings and will connect to internet
the user comes back with multitasking to my app, but doesn't press anything
I know I will get callbacks to the AppDelegate:
- (void)applicationDidEnterBackground:(UIApplication *)application
- (void) applicationDidBecomeActive:(UIApplication *)application
but the code ( it is not started by me) it is very big, and I don't want to handle there the UIViewController needs, if there is any alternative.
My UIViewController's - (void)viewDidAppear:(BOOL)animated it isn't called when the user came back.
The breakpoint it is not hited for sure!
Any usable ideas, except in AppDelegate?
You can use the notification center to listen to applicationDidEnterBackground within the view controller:
[[NSNotificationCenter defaultCenter] addObserver: self
selector: #selector(handleEnteredBackground:)
name: UIApplicationDidEnterBackgroundNotification
object: nil];
Do this in viewDidLoad. Similarily for applicationDidBecomeActive.
Don't forget to remove yourself as an observer in viewDidUnload.
The application delegate is the correct place to be handling application state changes, but just because that is the case, it doesn't mean you must put all the logic that is triggered by the application state change in there.
Put the logic where it belongs. If it's networking code, that's not in the application delegate and it's not in the view controller, it's in a separate class. Then look into ways of tying the different parts of your application together. In most cases, notifications, KVO and the shared instance pattern are good approaches to take.
Im trying to find a way to save data before my app enters multitasking, i know how to save data, but i dont know what method to use to save it before the app enters multitasking.
-(void)applicationDidEnterBackground:(UIApplication *)application{
this one? because i have everything set up to save, but it doesn't seem to be saving it, and im positive that its the multitasking part because it works on the ios 3 simulator. Do i have to save it in the delegate?
Thanks,
Jacob
EDIT: On the IOS 3 one i have it saving data in the
- (void)applicationWillTerminate:(UIApplication *)application {
Yes Jacob, You have to save it in the application delegate of your app.
The method -(void)applicationWillResignActive:(UIApplication *)application gets called when the device enters standby mode or when the app is switched to background.
So the saving part you can add to this method .
Also to make the app save data for iOS versions < 4.0 , add the saving code to applicationWillTerminate: also.
You should use the method what is the method Apple recommends
-(void)applicationDidEnterBackground:(UIApplication *)application
but you can also use
- (void)applicationWillResignActive:(UIApplication *)application
which is the method that is called instead of
- (void)applicationWillTerminate:(UIApplication *)application
Take a look at this Delegate method:
-(void)applicationWillResignActive:(UIApplication *)application
This allows you to react when the application becomes inactive. See the Docs for more information.
Happy coding :)
I am making a client server application for the iPhone and would like to know which method is called when the iPhone application is terminated. Any help would be appreciated.
The method relating to application lifecycle are UIApplicationDelegate methods. The two you want are:
- (void)applicationWillTerminate:(UIApplication *)application
- (void)applicationDidEnterBackground:(UIApplication *)application
If on a multitasking device, applicationDidEnterBackground: will be called instead of applicationWillTerminate:. In most cases, you can perform the same code in both callbacks.
- (void)applicationWillTerminate:(UIApplication *)application
in your appdelegate
The method applicationWillTerminate gets called when your application is being shut down. But the applicationDidEnterBackground/applicationWillResignActive methods are (now) infinitely more useful.
-(void)applicationWillTerminate:(UIApplication *)application in your application delegate will be called. Check this blog post with chart that describes in detail what messages will be sent during launch, termination and when transitioning between background and foreground.