I have built an ios application that is quite data sensitive, if the user exit the app, I need to make sure the input data are all gone. for example , if the user keying in the username and password, and exit the app, it need to empty out the fields so that after user enter again he will have to reenter data. The problem now is the login view controller is in swift , while the app delegate is in objective c. how should i do this?
You could use the UIApplicationDelegate methods
precisely the - (void)applicationDidEnterBackground:(UIApplication *)application; will be called when the app is going into the background ( user clicks the home button)
Find the documentation on this page applicationDidEnterBackground
Related
How is it possible to test / get notification about Facebook iOS app is just left?
Implemented Facebook Login button, and when coming back from FB login screen, need to do some extra steps in my app. But viewDidAppear is not get called in that view controller.
Do you have any idea? Need to use AppDelegate methods?
You can add an observer for UIApplicationWillEnterForeground notification.
And you could add some logic right before calling the facebook button, to check if the app has entered background because of that or simply because the user has pressed home button.
Is there any way to manage callback when user go through web view and click button - back to app?
You can bind the UIApplicationDidBecomeActiveNotification to an action do whatever you wish when you come back to your application. It should be thrown whenever your application gains back focus for any reason.
Note that this notification will be thrown every time you app becomes active, so make sure to unbind the action after it is called once. Also it will be thrown even if the user does not tap the back button, but goes back to home screen and reopens your app.
You can also use the delegate methods in your AppDelegate class and store the status of the app with some variables to determine when the user comes back to your app.
What I'm looking for is a mechanism to keep my app from resetting to the root view controller every time the application gets backgrounded or goes inactive. There are many apps out there that operate this way, namely Instagram, eBay, etc.
My instincts told me initially to poke into the AppDelegate's applicationWillEnterForeground method, where I would try to present the viewcontroller I'm after, however when I instantiate the viewController, I can present it, but without the navigation controller that normally be there.
This makes me think that I need to save the "state" of the application (maybe the NavigationController's stack?) and then restore the stack somehow when it gets relaunched.
I have watched the execution timings of each event and notice that closing the application and relaunching it will start the application fresh. I assume that my NSUserDefaults are still in place and thus could be checked for a logged in user. This could help determine which view in the navigation controller to push to (either login or dashboard).
Any direction is greatly appreciated.
The most revealing answer in this post was the use of some storage (NSUserDefaults) in order to store persistent data across uses.
For my specific case, this was storing a key holding user info. Then when the application loads, the would-be first view comes up, but if that key is missing, will modally pull a login view in front of it.
To do this I would use NSUserDefaults to store the current view of the app and then switch to that view when your app finishes launching. See the answers to this question: Swift: How to store user preferences?
i am developing an ios application that needs the user to login in order to get in to the system, if the user logged in and go to one of the view controllers in the application, then press home button. Now if he choose to open the application again (the application will enter forground), the application must redirect the user to the view controller he was viewing before he press the home button. Moreover, any data the user enters must be there.
Any Idea about how can I implement this in Xcode ?
Any help will be appreciated. Thanks :)
Save the viewController before app goes to background in the function applicationWillResignActive. And when app comes to foreground go to that viewController. If you have navigation based app, then call in applicationWillEnterForeground
[navigationController popToViewController:yourViewController];
How can I assign actions on iOS when a user presses the home button (exit)? I want this for an app where uses user a login feature and I want, upon exit, the user to log out. I dont want to use a button for this.
Use the method,
- (void)applicationDidEnterBackground:(UIApplication *)application
In your application's delegate.
You can't exit an application programmatically, you can use exit(1), however it's not a good practice, chances are there for your apps to get rejected from Apple.
applicationDidEnterBackground will be called for home button press. Try to handle everything here.
Write your actions in appDelegate's "applicationDidEnterBackground" method.