For iOS APP, Show custom snapshot when move APP from background to foreground - ios

Background:
Our app will need to work like below:
Manually move APP foreground => background (Timing1)=>(Timing2)foreground
Timing1:iOS will take snapshot
Timing2:iOS will show snapshot
Automatically move APP foreground (Timing3)=>(Timing4) background =>foreground
Problem:
At Timing4 iOS show snapshot taken at Timing1 instead of Timing3.
Analyse:
I think it is because at 2 situation our App moved automatically by other APP.So iOS do not have enough time to take snapshot at timing3 after "applicationdidenterbackground" method returned.
Question:
I want to force iOS to take snapshot which will be used for timing4.
SO
How can I force iOS use the snapshot I take instead the one iOS take by itself
At which step I should input code to release the function at 1.
Thanks.

Related

How to take a screenshot programmatically if the app is running in background

I am writing a piece of code using swift for iOS.
It’s using location services. I need to take a screenshot of the current screen every time the location gets updated.
The thing is when the app is running in background and updating the location the screenshots taken are from my app. Not the app which is currently available in the screen.
Assume that the user plays a game in their phone. But my app run in background and updating the location when the users location is significantly changed the screenshot should be taken and it should include the game. Not my app screen.
Can some one tell me how to achieve the screenshot capability I want.
Short answer: You can't.
Apps can only take screenshots of their own content. Starting with (I think) iOS 7 Apple blocked the ability of apps to take screenshots of anything but their own content. This is for security reasons.
Imagine your app echoes each character of your password as you type it, and then replaces it with a bullet as you type the next character. Now imagine an app that runs in the background and takes a screen-shot every time your app displays a new character of the user's password.

iOS app Killed and relaunched Showing my last VC

Killing and relaunching iOS app, If I have View Controller A,B,C last visible View Controller was C. So now when I relaunch app i see View Controller C for 10 sec and then shows up Splash Screen. How can I avoid this.
Because of this first 10 sec User cant perform any event on app.
I think this is an operation system bug. But if you want to avoid this, you can try to add a splash screen image view before your app will go to background. You need to add your custom overlay view as subview to current window. Use this method to implement this feature: applicationDidEnterBackground. You can find more information about this feature here:
Display a view or splash screen before applicationDidEnterBackground (to avoid active view screenshot)
To force iOS to launch an app with its default viewcontroller or launch image, you need to call
UIApplication.shared.ignoreSnapshotOnNextApplicationLaunch()
where you implement state preservation.
Form the documentation : Documentation
Prevents the app from using the recent snapshot image during the next launch cycle.

Modify iOS view while app is in background or in multitask view

I am writing an iOS app that keeps and displays the state of a system. It basically shows a light whose color represents state:
green/yellow/red light <==> OK/warning/danger
I'd prefer to show accurate state even when the app is backgrounded, and its snapshot is viewed thru the iOS multitask viewer (the view that looks like a rolodex, which you get after double-clicking the home button). I REALLY don't want to show a snapshot which displays an inaccurate state.
So my question is: can you change the view (or perhaps the app snapshot) while the app is in the background, so that when it's viewed in the multitask view it shows an accurate state.
I've seen that this is not recommended by Apple: from App Programming Guide for iOS
Avoid updating your windows and views. Because your app’s windows and views are not visible when your app is in the background, you should avoid updating them. The exception is in cases where you need to update the contents of a window prior to having a snapshot of your app taken.
However, Apple's music app does just this...if you start playing a playlist, then put the music app into the background, the cover art gets updated as the music app works thru the playlist. So this functionality must be possible somehow.
The best answer I can come up with after a bunch of searching is to alter my app's view to the splash image prior to entering background operation. This would ensure that inaccurate state isn't displayed, but also prevents showing accurate state.
You can change the snapshot view immediately before the snapshot is taken (A banking app, for example might want to obscure personal information), but you cannot continue to update the snapshot from the background once your app is suspended. You may want to adopt this approach in order to avoid displaying an inaccurate state; show nothing rather than stale data.
You might also want to consider some other options, such as a "today" widget that contains the updated status or posting local notifications when there is a significant change in status (such as entering the "red" state).

Background App Fetch and App Snapshotting

I am developing an app where I use iOS's "background app fetch" to keep the data of my app up to date. This is working fine except the "snapshot" of the app is not updated with this fetch.
When I say "snapshot" I mean the image that iOS takes when it goes into the background. This is the image that is displayed for the second before your app loads. At the moment this means users (particularly those on older phones) may see old information for a second or so then have it replaced with new information.
Does anybody know more about when the app takes the snapshot and if this can be forced (for example when I fetch new data in the background).
Alternatively can anybody think of a way I can achieve this effect?
Check out the documentations on Managing the State Restoration Behavior. It's not possible to update the snapshot once you loaded new data from the background. What you can do is to just tell the UIApplication to not show the snapshot but the default launch image using -ignoreSnapshotOnNextApplicationLaunch.
In my opinion however, this shouldn't be necessary. I can image that Apple will improve this with iOS 9.
How about resetting your app to a "neutral" state when it is about to enter the background? Displaying an empty table, for example.
You won't have the latest data, but you won't have wrong data either.

IOS state preservation: can I display a launch image instead of a snapshot

Question: When working with IOS state preservation, how can I display a custom launch image instead of the snapshot during the launching process
Description: I am working on IOS state preservation. Everything works fine except that every time I reopen the APP after killing it, the first thing the APP displays is the snapshot of the screen when the app enters background. I have a map view showing user's current location. I don't want the app to show the snapshot of an old location during launching and then jump to the current location. Is there some method to show a custom launch image during the launching process.
See the documentation for ignoreSnapshotOnNextApplicationLaunch :
As part of the state preservation process, UIKit captures your app’s user interface and stores it in an image file. When your app is relaunched, the system displays this snapshot image in place of your app’s default launch image to preserve the notion that your app was still running. If you feel that the snapshot cannot correctly reflect your app’s user interface when your app is relaunched, you can call this method to prevent that snapshot image from being taken. If you do, UIKit uses your app’s default launch image instead.
You must call this method from within the code you use to preserve your app’s state.
You can show a launch image when the app first starts up, I believe it's called 'launchImage', but it's a static picture. Apple encourages developers to use a launch image to show the user the UI while the app loads. Because you don't know if the OS will kill your app when it's in the background, and the user is traveling to different locations, it would not be possible to have the current location always ready to go when the app is brought to the forefront. You could show the user something else during the seconds it takes the GPS to get the coord's. You could put it in 'viewWillAppear'.

Resources