iOS 6 Saving/Restoring app state feature - ios

I'm trying to use the new Saving/Restoring app state feature on iOS 6, but (application:shouldRestoreApplicationState:) method is not called if I killed the app so it doesn't restore the app state, but If I'm running it from the debugger it gets called.
It worked when I added (Application does not run in background) in the plist and set it to YES, I don't want to set it to YES though. I was wondering if anyone got it working without setting the (Application does not run in background) to YES.

From the Apple docs:
The system automatically deletes an app’s preserved state when the user force quits the app. Deleting the preserved state information when the app is killed is a safety precaution. (As a safety precaution, the system also deletes preserved state if the app crashes twice during launch.) If you want to test your app’s ability to restore its state, you should not use the multitasking bar to kill the app during debugging. Instead, use Xcode to kill the app or kill the app programmatically by installing a temporary command or gesture to call exit on demand.
From experience, the easiest way is to put your app into the background by pressing the home button (or Command+Shift+H for the simulator). Then use the Xcode stop button. As the docs suggests, a debug exit gesture also works.
Update:
I found a small work around. The app saves its state in Library/Saved Application State/[Bundle ID]-[App Name].savedState/data.data.
When using the simulator, you can copy this file and drop it in anytime you want to restore to that specific state.
Similarly, on a device you can generate a .xcappdata archive from the organizer. Then, you can upload the .xcappdata archive when you want to restore from that saved state.

Related

is it possible to keep flutter app do not killed by iOS when running in background

I was wonder if possible to keep the app always rescue from backgroud? I am use an app writed using flutter in iOS, sometimes when I switched this app to the background, when next use it, will open a fresh state and lost the last state. is it possible to make the app always could keep the last state except exit app by user. So that the app would keep all the state of the last seem by the user.
You cannot prevent the operating system from killing your app. iOS kills apps to increase battery life and to free memory.
What you can do is to store some state to the file system with packages like shared_preferences or hive.
If you are using BLoC, you might also find the hydrated_bloc package useful.

iOS App Restarts After Changing Revoked Privacy Settings

No code to show, but merely a question on something that I'm sure has irked other developers/users.
When a user has revoked/denied permission to their Photos for a given app and then later changes to "Read and Write", the app resets/refreshes when opening it back up. Is there a way to not have the app reset/refresh when navigating back to the app? This is a concern because when the user is prompted to change their Photos permission, the user is deep within the app and now loses any progress made on that page after the permission is changed.
I am currently using Xamarin Essentials with Xamarin Forms, if that helps any.
It is designed by iOS system and your app is forced to restart when you change the privacy settings. I think there is no way to get around it.
You can try to save the state in the method applicationDidEnterBackground and restore it when user come back again after changing the setting.
Refer:
Having app restart itself when it detects change to privacy settings
App crashes in background while changing permission
There are some situations where your app gets killed and restarted: when it is swiped out, when your device is running out of power are turned off by the user, when the app is moved to the background and there isn’t enough memory for all apps, and as you noticed, when certain settings change.
The reason for the restart on settings change is that your app might be doing things that get disallowed, or it might never notice things that are suddenly allowed; many apps check these things once when the app starts, so restarting it is guaranteed to make it work correctly.
You should have code that saves the application state when the app goes in the background, and restores the state when the app is launched. That fixes not just your problem with permission changes, but will also restore the app after being swiped out or killed while in the background.

How to close iOS app completely (wipe the RAM it uses) when switching to another app/homescreen

I have a React Native app. When its not in the foreground it needs to be closed completely. The content of its memory must be gone and I would also like to wipe the cache.
Is this possible at all and if yes, how?
If you set the info.plist key UIApplicationExitsOnSuspend to true then your app will be terminated when the user presses the home key rather than moving to the background.
UIApplicationExitsOnSuspend (Boolean - iOS) Specifies that the app should be terminated rather than moved to the background when it is quit. Apps linked against iOS SDK 4.0 or later can include this key and set its value to YES to prevent being automatically opted-in to background execution and app suspension. When the value of this key is YES, the app is terminated and purged from memory instead of moved to the background. If this key is not present, or is set to NO, the app moves to the background as usual.
Any cache files that your app has created "on disk" will need to be deleted by your app in applicationWillTerminate. Note that this method may not be called if the user terminates the app or the battery goes flat, so it is probably best to avoid persisting any sensitive data to disk.

Does core BLE run in the background after force quit in iOS 7.1? Or just iBeacon?

Does anyone know if core BLE continues to run in the background after a user force quits the app in iOS 7.1? Or does just iBeacon continue to run? I know that neither will continue to broadcast on force quit, but will both continue to scan?
EDIT: I've attempted to test the current implementation I've had and it doesn't appear to be running in the background after force quit. What I've heard so far from other sources is that it does but it doesn't appear to be running for me with the standard CoreBluetooth implementation.
For CoreBluetooth (CBCentralManager and CBPeripheralManager), the following rules apply:
If the user closes the app manually using the app switcher, the BLE part of your app also gets killed.
If the user does not close the app manually, you can use the bluetooth-central and bluetooth-peripheral background modes to get relevant callbacks while your app is backgrounded. However, iOS may still kill your app under memory pressure or for whatever reason, in which cases the BLE part is also gone.
To keep the BLE part alive, you can use restore identifiers when instantiating CBCentralManager and CBPeripheralManager. Managers with a restore identifier are kept alive even after iOS killed your app, and if an interesting BLE event occurs), your app will be launched into background and you will be passed the state of the managers when the app got killed for restoration.
The main queue is suspended during background execution - make sure to configure the managers in a way that events are not dispatched on the main queue.
If the user closes the app manually using the app switcher, restoration is forfeited and the BLE part of your app won't stay alive.
To test restoration, you need to resolve to using tools like BackgroundKill. Note that the Xcode debugger may keep your app alive, so make sure to disconnect the debugger first (which will kill the app), then launch your app, then open BackgroundKill and examine the Console output in the Xcode Organizer window.
Yes, it continues to run. This is a change in iOS 7.1.
See my detailed answer and test procedure in the comments here: https://stackoverflow.com/a/22365156/1461050

Having app restart itself when it detects change to privacy settings

I have an app that uses the ALAssets framework to access to the users photo library. I wrote some code that detects whether or not the app has permission to access the photo library, and if it doesn't, I display an alert message which tells the user to turn on location services for the app in settings.
Problem is, when the user manually changes the privacy settings and then they reopen the app, iOS forces the app to crash with SIGKILL.
I've noticed that the way another app handles this is by somehow detecting a change in the privacy settings, and forcing the app to restart the next time the user opens it. Does anyone know how to accomplish this?
You misunderstand what is happening. Your app is not crashing (though it may appear so if you are running the app with the debugger).
When you switch to the Settings app (and your app is suspended in the background) and change the privacy settings, suspended apps are terminated. When you switch back to your app, it is simply started again. This is no different than your app being killed for any other reason.
It is up to you to code your app to handle this by restoring its previous state. The other app you talk about is simply returning the user to the previous state. Many apps do this. It has nothing to do with being killed due to privacy changes. The app would restore state when being killed for any reason.
You can check whether you're authorized to access the photo library using the authorizationStatus class method of ALAssetsLibrary. You should check this value in some method that will be called each time your app "opens", and update your UI accordingly.

Resources