How to show specific viewController in AppDelegate when receive notification? - swift

[![enter image description here][1]][1]I am now working on voip call app in swift. This app use user authentication when app is opened.
So UINavigationController is the rootViewController of main window and loginViewController is the rootViewcontroller of the navigation controller.
After login, app shows main screen of call history.
But now I want to show call screen when notification is received and app is in background.
How can I do this?

Related

iphone development: launching app on receiving push notification

In my app I can successfully receive push notifications. However, if the app is in the background, when I open the app I faced with the last state of the app. What I want is, even if the app is on background, opening the notification should relaunch the app like it is the first time the app is opening. Is that possible?
In your AppDelegate you could react to the receipt of the notification and restore the application state in a way that is appropriate for your app.
For example if your main view controller is a UINavigationController and the user may have navigated down in the view hierarchy, you could just pop back to the navigation controller's rootViewController:
[[self navigationController] popToRootViewControllerAnimated:YES];
I don't know if you could relaunch the app programmatically but if you open the app from a notification the
application:didReceiveRemoteNotification:
from the UIApplicationDelegate gets called, then you could do there whatever you want to do

How do I manage a login view in a navigation-based app?

I am designing an iphone application in objective C.
As of now, I have a UINavigationController in the beginning of my application
and rest of the navigation was being handled from it.
Now I want to insert a login screen when the application is loaded.
How do I make it independent of my rest of the application ?
i.e. As of now, I created a LoginViewController and added it to the NavigationViewController
of my app. When the user successfully logs in, the application continues with the next screen being pushed into the Navigation Controller.
But the problem with this approach is that, I can still go back to the initial login screen from the navigation item.
I have tried to hide the navigation bar from the first screen after login, but it removes the navigation bar from each of the subsequent screens.
The only working solution I can think of is that, I should manually hide the navigation bar in the start screen and make it visible in the subsequent screens.
Is there any other sane approach ?
I'd probably do your nav controller disregarding the login screen, and then present the login screen using presentModalViewController:animated:
present your LoginViewController in viewDidLoad for the the navigationController once the user login you dismiss it and continue your screen's flow as you want. also you can store that user login your app in the NSUserDefault so you can check this value and present the loginView in case he didn't login otherwise you show the navigation screen as normal
If the user have not login in the app show LoginViewController and don't allow the user to go to navigation controller till then. Once login don't show LoginViewController directly show navigation controller so that user dont have to sign again and again.. To store user login information use NSUserDefaults. Retrieve the info at loading of the app and display controllers accordingly.
Cheers
You need to store in UserDefaults some value - auto login / did login and when app is start you check this value if user isn`t in system u need to create login view controller and present it modaly.
Before your first view appear u need something like this -
BOOL didLogin = [[NSUserDefaults standardUserDefaults]boolForKey:#"isLogin"];
if (!didLogin) {
LoginViewController *loginVC = [[LoginViewController alloc]init];
[self presentModalViewController:loginVC animated:NO];
}
and when user is login you need to save value in user defaults
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"isLogin"];
if you vant auto login feature you must store password in keychain
I would suggest to hide back button at your firstviewcontroller and unhide in rest all viewcontrollers.
-(void)viewWillAppear:(BOOL)animated {
self.navigationItem.hidesBackButton=YES;
}
Otherwise another solution is that present the loginviewcontroller in the viewDidLoad method of your firstviewcontroller and as login completes dismiss the presented logincontroller on login button.
Even its the standard method to implement, all apps having login facility would have this type of flow.
Hope this will help you out.

When notification fires, "slide to view" shows a specific controller. Is this possible?

I have an app in which I'm using push notifications. What I really want to do is when a user slides to view from the lock screen he should be able to go to a specific view controller, and not just simply open the app.
Is this possible? Can anyone direct me towards right direction?
Thanks a lot!
In your application:didFinishLaunchingWithOptions: method you can check whether your app was started due to a remote notification by looking into the launchOptions dictionary. The key UIApplicationLaunchOptionsRemoteNotificationKey will give you the remote notification, if any, and you would then need to present your view controller.
If your app is still running while the remote notification arrives your app delegate's application:didReceiveRemoteNotification: method is called.
See the UIApplicationDelegate documentation.
The app needs to figure out and show the right view controller when it is opened after a push notification.

Proper viewController setup for iPhone with login and logout functionality

In developing my current iPhone application, I'm having issues handling the login, logout functionality of presenting views.
I'd like to have my application have the following flow, but I cannot seem to figure out the proper viewcontroller setup:
When a user is not logged in, a login screen is immediately presented. Upon a successful login, the main application is displayed. The main application is a TabBarController. When returning back to the application, if you have already logged in, the login window will not display, but immediately go into the main tab bar. Once in the app, you can "logout" and it will take you back to the login scren.
Please let me know if I need to go into further detail. There are a few other questions on here that are similar but not exactly what I'm looking for.
Thanks!
I would consider two ways of doing this:
have the login screen be a modal view controller that pops over the main UI.
e.g.
if (currentCredentials == nil) [self presentModalViewController:loginView animated:YES];
or alternately, handle switching between views using your app delegate.

Launch application from alert view of push notification

How can i launch my application when user taps the view button in the alert that came due to push notification?
It happens automatically. When the user taps the "View" button, your application will launch and your application delegate will receive the -application:didFinishLaunchingWithOptions:. If your application's already running and in the background, I believe it receives the -application:didReceiveRemoteNotification: message, probably just after it gets -applicationWillEnterForeground:.