application remains previous state when enter from background in ipad? - ipad

i have noticed that my ipad application remains in previous state (state when i closed the app) when it coming from background. i have checked the plist and delegate methods fro this problem. actually i have a web app that uses UIWebView . i cant figure out wot the actual problem is. i dont want my app to work in background and it should start from the initial each time it opens.
is this problem related to cache memory? do we need to delete the cache memory when the app closes?
need some help

Try adding this to the Info.plist file.
UIApplicationExitsOnSuspend=YES
As a boolean value. It does not allow the application to run in background.

In fact users expect apps to return to the place where they left it. On iOS there's no real (user) distinction between apps that in memory but not in the foreground and apps that have exited.
Having said that, there are two ways of doing what you want:
Try adding the UIApplicationExitsOnSuspend flag to your Info.plist
Reset your UI either in the send to background or bring to foreground notifications

OKAY, SORRY.. I FOUND THE SOLUTION MYSELF.
i just put this field "application does not run on background" on info.plist
now the application will start from its initial state each time it opens.
thank you,

Related

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.

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

App in background swift iOS

i have a big problem. I am working on an app about accessibility. The app should work through the iPhone microphone to take over sounds from the environment (indoor) and compare them in real time with sounds in the app database (recorded from users previously). If sounds match, the user will be warned by the app through a notification. So... firstly, the app should listen sounds working in background, but after some minutes, iOS closes the app in background automatically. IS THERE SOME SOLUTIONS FOR THIS PROBLEM? TO ALLOW THE APP BE OPENED AND WORKING?
Secondly, do you know in which way is possible compare sounds recorded with sounds listened by microphone in real time?
Really really thank you. 🙏🏻
Regarding the problem that your app is automatically closed, it seems that something was not configured properly in your project.
When the UIBackgroundModes key contains the audio value, the system’s
media frameworks automatically prevent the corresponding app from
being suspended when it moves to the background.
Make sure that you have enabled the "Audio, AirPlay and Picture in Picture" background mode in your project.
Fore the first question:
Because your app will be recording the audio while in background, you can:
set UIBackgroundModes key in your app’s Info.plist file to audio.
It should keep your app alive when you press Home button. See the Declaring Your App’s Supported Background Tasks section
At some point, iOS can kill your app due to some conditions, but
eventually it would restart your app later.
And be careful with this, you might have to deal with Apple Review team to prove that your app is not doing something harm to user privacy. Otherwise, they wouldn't let it go live.
For the second question:
I think you can use some AI/Machine Learning service out there to do so. It's much more accurate and faster than building it your own.

Running IOS Application in the Background new developer

I am new IOS developer using swift. I have created a Radio App (streams Live). I want to make it to run in the background when user minimize the app or do some other stuff. Right now, it stops streaming audio as soon as sent to background and continuous again as soon as it is brought to foreground.
I searched few articles and other forums, but couldn't find any help. I am really new to IOS development and don't know about controls/functions in the AppDelegate.swift.
So far I enabled the option under Project Capabilities Tab as following also made change in info.plist file, however Application still stops as soon as enters in the background.
Any word of advice will be greatly appreciated. Thanks for your time and views.
I have adding the bool to info.plist file saying "Application does not run in the background = "NO"
Now I can run app in the background. I hope this solve the problem for others as well.

UIAutomation : Change location when the app is in background

I am working on UIAutomation. I need to change the location when the app is in background. I have tried following line of code:
var target = UIATarget.localTarget();
UIATarget.localTarget().deactivateAppForDuration(30);
target.setLocation({longitude:77.50, latitude:12.50});
but target.setLocation is not getting called until the app comes to foreground.
Could any one please tell me how I can change the location when the app is in background.
Unfortunately UIAutomation can only automate the application it's attached to. When the application is not "active", it has nothing to talk to. Using lockForDuration, deactivateAppForDuration , etc blocks while it relinquishes control to the system, making your app inactive. While the application is in that state UIAutomation can't send it any more messages.
I would recommend filing a radar asking for the ability to set the location while the application is inactive.
When I ran into a similar problem in the past I had to use AppleScript to change the location of the simulator to get the effect I needed.
You have since updated your comments indicating you are testing a navigation application. Well! That's a little different. If you do not ACTUALLY require UIAutomation and were only trying to use it as a way to set the location:
Xcode does allow you to simulate a route using GPX files, and this CAN be used with Instruments.
Find an appropriate GPX file, preferably one that is a track.
Go to the scheme for your project. In the Run action, go to the "Options" tab. Check "Allow Location Simulation" and use the drop down list to add your GPX.
Run your application from Xcode.
...
Profit!
I think you can use update part in background as service. Though i am newcomer in this world. You can try this. Thanks
if you want your app to execute methods in background, you have to enable "background mode" in your capabilities tab of your app. you have to choose a mode, for example "location updates". but be careful: apple has restrictions of what kind of apps are allowed to run in background. the "location updates" mode are only allowed for apps like navigation apps. see the app store guidelines for details.
if you dont set the "background mode" to yes, your app has 5 seconds to finish executing tasks after turning to background and then all tasks will be stopped and never called until your comes to foreground again.
Refer the http://code.tutsplus.com/tutorials/ios-7-sdk-working-with-background-fetch--mobile-20520 for the Background fetch. I hope this helps you.

Resources