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
Related
[![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?
Hi I am new to iPhone development, I am developing a TabBar app it's contains 5 tabbar Items.
When I am close app at third TabBar viewController screen and again when I am opening app that time same third TabBar viewController screen only opening.
How to set App first screen as a default App opening Screen in iphone.
I need to set first screen as a default opening screen when ever open a app.
Could you please share your ideas here..
When you close the app, it doesn't KILL it, it just suspends it. Unless you set the option to kill it when you close it.
I suggest you read Apple Documentation For Application Flow
And possibly read the other documents Apple have provided for you there if you are new to all of this.
In your application's Info.plist, add a boolean key UIApplicationExitsOnSuspend with the value YES.
This will always exit the app (instead of running in background) when you close it. On opening app again, first view controller will appear instead of where you left it last time.
This is because you are setting your application to be run in background, so whenever you close your app the app will run in background and resume on startUp.
so just do one thing
Go to your info.plist and set value for
Application does not run in background to YES
If application is killed by default it loads all settings in Application Delegate method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Here you can modify your root view controller, which I presume is some kind of tab bar view controller.
So there is probably some code in that method which defines which tab to load.
However if you want to show specific tab after application enters in the foreground use Application delegate method:
- (void)applicationWillEnterForeground:(UIApplication *)application
Or
- (void)applicationDidBecomeActive:(UIApplication *)application
When exiting the app by for example pressing the home button on the iPhone the app is not terminated. Instead the execution is suspended but the app will remain in memory until iOS decides to remove it. This means that when you enter the app again it will be in the same state you left it. You can see if the app is still in memory by doubletapping the home button.
When your app becomes active the method applicationDidBecomeActive: in your UIApplicationDelegate will be called. You can implement that method to set the state you want your app to be in when it is restored.
I would not recommend explicitly killing the app when it is suspended. That forces the app to be reloaded each time it is started which will degrade performance.
For more information see Apple's documentation on app states.
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.
After an iPhone app is put into background, then the user clicks on it again and it comes back to foreground, THEN
Question - How to tell what is the current UIView/UIController after an iPhone app in brought back to foreground?
I know that the application delegate's applicationDidBecomeActive method can be used to trap the return to foreground. I also know that each controller could subscribe via notification centre to UIApplicationDidBecomeActiveNotification.
But if what I want to do is reload the UI data in the UIView/UIController that is displayed, and not carry out this same operation through all other view/controllers, how can I tell which is the one to do the reloadData on?
If your using a nav controller, you can use this:
self.navigationController.visibleViewController
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:.