iOS Application is lauching again once it is closed - ios

In IOS 4 if the application is closed by user manually then it is not launching again it crashes when launched and i cant do anything.
I am testing it on Ipod4
When i pressed the hard key of ipad twice and close the app manually then i am not able to start the application again.
how to terminate the application completely do i need to write something in
- (void)applicationWillTerminate:(UIApplication *)application
of appdelegate?

Seems like you have some serious issues with your code.
An application should support both going into the background and transitioning out of it into active state again, as well as terminating from the background once that is initiated by the OS, or by the user via the 'double home tap -> close' action.
Terminating the application forcibly through code is not supported and will actually result in apple rejecting your app when you submit it.

Related

How to prevent termination of main app when the service is in foreground?

I'm currently trying to remake our company app that has been outsourced. We do not have access to the source code so its not possible to look at the code. Our outsourced app has a service running in the foreground with a notification. When the outsourced app is closed by the user in the open app list (I'm unsure what it's called) it doesnt really close. Its behavior is almost like it's being minimized. When opening the outsourced app after closing it opens immediately right where it was last left off like it was never closed. Not even a splash screen. It's behavior is like its being resumed.
I've been able to run a foreground service with binding and unbinding following the sample ForegroundLocationTracking embarcadero has given. The app stays open despite the user going to the home screen or locking the phone. The problem comes when the app gets terminated by the user from the open apps list. The app is now terminated and the service briefly gets terminated but gets started by the system again.
My thoughts are that the outsourced app is running a remote service however I'm unsure.
How can I make the app have the same behavior as the outsourced app? The service will keep running in the foreground. No briefly terminating and starting again. The main app must also just resume like the outsourced one does or have the same behaviour.

Perform a hard close of iOS app and reopen with saved state in simulator w/ automation

I'm attempting to automate a hard close and relaunch of an iOS application while retaining state in the simulator.
Googling tells me to add a button to my app to call exit(0), but that's resetting app state despite a number of threads saying it doesn't (although Apple said it's unreliable for this a long time ago).
Another thread said to use abort, but that's akin to throwing an exception and definitely not the right thing.
Performing the [automated] manual steps (double click the Home button and swipe the app up to death) disconnects the debugger so another option failed.
The correct procedure for testing state restoration is: click the Home button on the simulator once so that the app backgrounds and saves state. Now, back in Xcode, stop and relaunch.
You can simulate a click on the Home button like that
XCUIDevice.shared.press(.home)
And then call this function to launch your app with
XCUIApplication().launch()
According to the launch() documentation, it should terminate your app and relaunch it :
* Launches the application synchronously. On return the application ready to handle events. If the
* application is already running, the existing instance will be terminated to ensure a clean state
* for the launched instance.
*
* Any failure in the launch sequence will be reported as a test failure and the test will be halted
* at that point.

iOS app entered background and still in background for more hours without killing

I have searched a lot on this but unfortunately, couldn’t find a fruitful answer. Can anyone help me on the below?
In my app, I have three simple ViewControllers and currently I am in ThirdViewController. Whilst, if I receive a phone call, automatically my app will go to background and applicationDidEnterBackground delegate would be called.
Then, if I forget to open or kill my app which is in background and after 8 hours, if I try to open it from background, it is not resuming from ThirdViewController instead it is relaunching from LaunchScreen.​
My question:
I would like to understand the reason behind this (my app not resuming from ThirdViewController instead it is relaunching from LaunchScreen)
While my app is in background will there be any communication between my app and iOS. If yes, how I can handle it through my app?
But, within 15 mins, if I re-open app from background, how App gets maintained Application state, that is showing ThirdViewController?
If my app is in background for some hours, at that time application states not get maintained. How that Application states get cleared? Either in App level or OS level.
If yes, how to handle this?
PS: I don't want to go for UserDefaults or other persistence storage concepts.
Screenshot:
u will need to save the application state and restore state when the app will relaunch.
try this
https://www.raywenderlich.com/1395-state-restoration-tutorial-getting-started

iOS: Handling interactive notifications when app is not running in background

I am trying to implement interactive local notifications for my app, and in particular via implementing this method:
- (void) application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void (^)())completionHandler
The method works fine except if the user kills the app and then receives an interactive local notification. In that case there is no indication that the local notification action (button click) was received.
I am looking for help/advice on 2 fronts
(1) Is anyone able to confirm/deny that handleActionWithIdentifier is not called when the app is not running at all (i.e. not even in background mode). I went through the relevant programming guide and I noticed that much of the language talked about foreground and background mode without addressing the third possibility. However, I'm looking for something more solid than 'it doesn't work for me' to put this to rest. Is there anything in the docs that says these should or should not work after the app is killed?
(2) How can I log in the Xcode console after I have killed my app? Every time I try this, I notice that when I relaunch the app I no longer have logging. This is important because I need to prove one way or another whether I receive interactive notification messages from user clicks after the user has killed the app.
I would appreciate any and all advice on this matter. Thank you.
If the app is terminated then when it gets launched via the notification then didFinishLaunchingWithOptions gets called with a key of UIApplicationLaunchOptionsLocalNotificationKey. The value of this key is an NSDictionary containing the payload of the local notification
You can't log in the Xcode console from the app if the app isn't running of course. But if you run the app not via Xcode you can watch the output by going to Window|Devices then selecting your attached device.
If you are relaunching the app via Xcode and logging isn't there this is probably a bug in Xcode, I've noticed recent versions of Xcode is having problems displaying logging. If this happens try the Devices output.

iOS 7 Background Fetch When the App is Not Running

I've written a simple application in order to test and monitor how the background fetch feature works in iOS7.
First of all, I've set UIBackgroundMode options in my Info.plist file.
Then;
I added to below code into application:didFinishLaunchingWithOptions: method in AppDelegate.m:
At last, I've implemented the application:(UIApplication *)application
performFetchWithCompletionHandler: method as requested.
Every time I click Debug->Simulate Background Fetch button, it changes the application's batch number and works as expected.
However, I've never been able to make it work when the application is not running (not even in the background mode, just not running).
Apple says that when the application is not running and OS wants to execute the following methods respectively:
application:(UIApplication *)application didFinishLaunchingWithOptions:
applicationDidEnterBackground:(UIApplication *)application
application:(UIApplication *)application performFetchWithCompletionHandler:
So my question is that is there a way to test background fetch when the app is not running?
I am testing this on my iPod 5th Gen with iOS 7.1.
Edit 2: Note that if a user kills the app from the app switcher, the background fetch will never happen again. This is working as Apple intended. See the related "Understanding When Your App Gets Launched into the Background" docs for details:
In most cases, the system does not relaunch apps after they are force
quit by the user. One exception is location apps, which in iOS 8 and
later are relaunched after being force quit by the user.
And an old developer forums post (the link unfortunately no longer exists)...
"If you kill an app from the multitasking UI, the system will never
automatically launch the app again. The logic here is that, if the
user has killed your app, they probably want it to stay dead."
You could make a simple GET request, eg: "http://dev.example.org/?ping=1" to your web server then grep the access.log on the web server for "?ping=1"
Edit: Another method to test the app being launched in the background (eg: without being able to double tap the home button and switch to it) is by creating a background-only scheme. Go to Product -> Scheme -> Manage Schemes and then duplicate your default scheme.
Then edit the new scheme and click the Options tab and check "Launch due to a background fetch event" - when you run your app it'll be launched directly into the background, as it would through normal use.

Resources