back to previous controller before application enters background - ios

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];

Related

Swift Xcode Switching between View Controllers - Navigation between View Controllers

I'm using Firebase in my app, and every time user launches the app - I need to check if the person is logged in. And if the user is logged in - I need the Home View Controller to be opened, if the user isn't logged in - I need to open the Log In View Controller. How do I implement it in my mobile app?
You can go through the Firebase Documentation, and if you see carefully enough, there is a function to get the current user email ID and the custom ID allocated to the user by FireBase. If these 2 parameters are nil when you start up your app(in your first screen), then you can performSegue(xx,yy). else you can directly go to the home screen.
You can use Boolean User Default in your app to keep track if user has already logged in before. If true then you can navigate to Home View controller else navigate to Log in view controller. You can find more details on User Defaults Here and Here

How to know coming back from Facebook?

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.

Callback for when the application regains focus back from a redirected app

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.

ios: programmatically ask for Game Center sign-in?

I have a simple question, but I’ve looked through Apple’s documentation and done some searching and I can’t find the answer to it.
Is it possible to programmatically pull up Game Center’s sign-in view? I have a UIButton that requires Game Center, and if the client does not sign in when the app is opened (iOS pulls up the sign-in view at launch), I want to provide a second chance for the user to sign in.
I'm assuming you're calling this GKLocalPlayer method on launch: -setAuthenticateHandler: (>= iOS7) or -authenticateWithCompletionHandler: (<= iOS6)
If the user cancels the presented login screen, calling these methods again does nothing, or rather, the completion handler is called with an error. The user will then need to login to GameCenter through the GameCenter app or through the Settings app. (While testing, you can login through the GameCenter app, then logout. After that the screen can be presented in your own app again.) You can show an UIAlertView telling the user to login through the GameCenter app.
Alternatively, and I don't know if this is allowed/approvable, but in iOS7 the authenticateHandler has a viewController parameter holding the login screen. If you store this login view controller in an instance variable and the user cancels login, you can present the login screen again later using a UINavigationController.
If you try to present the saved login view controller with -presentViewController:animated:completion: the view controller's Cancel button no longer works, but using a UINavigationController hides the Cancel button and allows navigation back to your own view controller.
You'll also need to hide the login screen manually after the user logs in by responding to GKPlayerAuthenticationDidChangeNotificationName. It doesn't seem like developers were intended to be able to do this, so it may not pass approval, but it works!

Programmatically logout in iOS application

My iOS application contains login page. And after entering the app there is a logout button. When a user presses the logout button programmatically I want to show login page again as if the user is logging first time. Could you please suggest how I could implement this in my iPad application.
I do this in my app. I have a tabbarcontroller that i use for logged in users. When they log out (or for first time use) I message the appDelegate that removes the tab bar from the window and makes the login view the root view. Once logged in, that view is replaced by the tab bar controller.
I even go a bit further. On each switch I totally release all the other objects, and so I know for sure that when user sees any of these views it's completely 'fresh' and only uses the defaults for anything custom to that user.

Resources