Prevent IOS to relaunch an app when I switch app to Facebook in safari - ios

I am really stuck on this problem and I need your help! I'm doing an iPhone app.When iPhone swap between app and Facebook redirection in safari , iPhone shutdown the app for memory saving.
What I am doing is I am providing fb sharing in background from my app.
When I am doing fb sharing its shares successfully in background and comes back to my app successfully.At that time my app is not crashing. But when I go to safari and type Facebook and open fb site to check my shared post , in background my app is crashing.
This issue is coming in iPhone with iOS 7, I am not facing this issue in iOS 8.Check this post : Prevent IOS to shutdown an app when it app switch to facebook for login and permission request but this solution doesn't work for me as I am using pod to install fb and doing background share.

Though it's too late to answer this but I believe it may be helpful for others.
In App Programming Guide for iOS under "Being a Responsible Background App" section it was said that
your background running app would be terminated if it doesn't follow one of the given requirements.
You can familiarize with the full documentation. I'll quote 2 of them which exactly fit your problem:
Being a Responsible Background App
The foreground app always has precedence over background apps when it comes to the use of
system
resources and hardware. Apps running in the background need to be
prepared for this discrepancy and adjust their behavior when running
in the background. Specifically, apps moving to the background should
follow these guidelines:
Do not make any OpenGL ES calls from your code. You must not create an EAGLContext object or issue any OpenGL ES drawing commands
of any kind while running in the background. Using these calls causes
your app to be killed immediately. Apps must also ensure that any
previously submitted commands have completed before moving to the
background. For information about how to handle OpenGL ES when moving
to and from the background, see Implementing a Multitasking-aware
OpenGL ES Application in OpenGL ES Programming Guide.
Do minimal work while running in the background. The execution time given to background apps is more constrained than the amount of
time given to the foreground app. Apps that spend too much time
executing in the background can be throttled back by the system or
terminated.
To sum up, maybe your app is doing one of the above-given tasks when it's moved to the background after Facebook sharing.

Related

How to avoid iOS app being terminated by system too often when in background

I'm building an iOS app for iOS 8 & 9 and I am facing the problem that when the app goes to background the system is terminating it after just 2 or 3 minutes.
My testing is easy:
I kill all running apps from my iPhone.
I restart my iPhone (to ensure no other apps are taking memory).
I launch my app.
I do nothing inside my app.
I press the "Home" button, moving my app to background.
I wait doing nothing else for 2 or 3 minutes.
I open my app again and surprise, the system has terminated it and now it is restarting as a new launch.
Some comments:
The app does not use CoreLocation in background neither any other service.
I've profiled the app, trying to understand if it is consuming too much memory. When moving to background, it consumes around 25Mb of RAM memory. I'm attaching a screenshot below.
This behavior has been tested on iPhone 5, 5s, 6, 6+.
In iPhone 6s and 6s+ seems to take a bit more time to happen, but still happens.
My question is: Do you know why would this be happening? anything I might not be considering or just forgetting?
I don't want to force my app to run in background by using CoreLocation or something similar. And I'm ok if the system kills my app eventually. What I don't want is that everytime I move my app to background the system terminates it.
Any hint or help will be appreciated.
Thanks,
All applications are automatically killed by the system
According the Apple documentation:
App Termination
Apps must be prepared for termination to happen at any time and should not >wait to save user data or perform other critical tasks. System-initiated >termination is a normal part of an app’s life cycle. The system usually >terminates apps so that it can reclaim memory and make room for other apps >being launched by the user, but the system may also terminate apps that >are misbehaving or not responding to events in a timely manner.
Suspended apps receive no notification when they are terminated; the >system kills the process and reclaims the corresponding memory. If an app >is currently running in the background and not suspended, the system calls >the applicationWillTerminate: of its app delegate prior to termination. >The system does not call this method when the device reboots.
In addition to the system terminating your app, the user can terminate >your app explicitly using the multitasking UI. User-initiated termination >has the same effect as terminating a suspended app. The app’s process is >killed and no notification is sent to the app.
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/TheAppLifeCycle/TheAppLifeCycle.html#//apple_ref/doc/uid/TP40007072-CH2-SW1
You can track position but you will certainly see a blue status bar to indicate that an application use GPS tracking.
Maybe you can try to "wake up" your app in background with silent notification...
If it is not necessary to keep your app alive, trust the system...
Some error in inside your code. Please select debug Navigator before run your app... Now you can able to find your error..
Or too much memory also it will terminated..
Apps which are running in the background drain battery life faster, It gives you a bad perception of the device, instead of the app, because the average consumer has no idea that it's an app draining battery.
Thus iOS won't allow your app to run in the background, more than a few seconds. But there are some exception, an app can request extension to this by declaring that its starting a Background Task.
for more info you can check below links:
http://blog.dkaminsky.info/2013/01/27/keep-your-ios-app-running-in-background-forever/
http://www.speirs.org/blog/2012/1/2/misconceptions-about-ios-multitasking.html

IOS limitations when running on background

I searched informations about possibilities when running an iOS app on background, but I didn't found same on different sites.
My application has to read the battery level (with step of 1%) and the time, but I don't know if I can read that when running on background.
Please if someone is sure about it or know a site to read these infos, it will be very nice.
EDIT : I've one more question, can I just open my app (to perform more actions) when the notification center return a battery state under 5% for example ?
No, you can't.
It's not possible to let your app running on background, it's iOS system's limitations.
In iOS 7.0 and later, you have opportunity to do some pre-fetch stuff even your app is not running, through the method like application:performFetchWithCompletionHandler:, but you should tell the device by posting remote notification from your server.

Application does not work properly in background without Xcode

I'm building an activity analyzer application for iPhone and I use iOS 7. In order to do these i use CMMotionManager and I access accelerometer data.After this I write the datum to database. My application has to work also in background and I used queues, GCD, blocks and other such things in my code to do this properly. Problem is, all of these are working properly when iPhone is plugged in with Xcode but if I run the app without Xcode, app runs about 4 or 5 minutes.After, it is terminated.What is the reason for this?
iOS apps can only run in background, if they fit in one of apples defined background modes such as "App registers for location updates","App provides Voice over IP services","App plays audio","App processes Newsstand Kit downloads","App communicates using CoreBluetooth"",App shares data using CoreBluetooth" and a few more. All background modes you will find in xcode in the capabilities section auf your project(click on project name upper left->mainwindow->second tab).
if your app fits into one of these modes, you must enable this in your app.plist by setting the checkbox in the capabilities section.
if your app doesn't fit in any of these modes you can run in background only a limited amount of time and then iOS stops all activities.
For testing you could start any background mode. but when your app shall be reviewed for deploying via app store apple will reject the app if you use the background mode without legitimation.
The reason for this is that iOS 7 (actually all versions of iOS) will suspend a background task, and potentially terminate it if it's misbehaving, only certain kinds of apps can keep running. Here is the apple doc on it: https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW20
So, given your situation, you'd most likely have to "lie" about what type of app your app actually is, which will get you rejected from the app store.
If you do decide to go the route of a hack, be very careful about battery life, cpu usage, and memory usage, as there is a reason apple did this.
FYI: The "type" is set in your Info.plist file.

Enable download in background with phonegap ios app

I am using phonegap 2.2.0 to develop an ios app. The app requires to download some videos which i'm doing with the FileTransfer. The problem is if the app goes background i.e if the screen is locked or if the home key is pressed, download gets cancelled. I need to continue downloading the videos even when the app is in background. Is there any workaround for this?
The problem is that your app gets suspended after a short period of being in background mode, so it is no longer executing code. You need to either declare and implement your app as a service (UIBackgroundModes in Info.plist), or delay the suspension (in applicationDidEnterBackground handler). Both cases are tricky if you are a pure PhoneGap developer.
I wrote a small PhoneGap plugin for iOS that checks whether the app has called for background mode, and if so prevents it from getting suspended (normally up to 10 minutes) until the mode is revoked.
See this article for more detail.

Running an app function from background- iPhone

I need to create an app which can handle movement events while running on the background.
i.e each time an accelerometer event is happening it should be tracked in the application memory-when the application is running in the background.
My questions are :
1. Is it possible on IOS?
2. How can it be done?
(I came up with some relevant questions but i'm not sure that the answers are up to date due to IOS changes.)
Thanks,
Asaf
You should have a look to this thread (and the links inside) and the apple documentation.
To summarize no third party apps can run in the background (even though some of apple apps do this) excepting for:
Tracking the User’s Location
Playing Background Audio
Implementing a VoIP App
Downloading Newsstand Content in the Background
Communicating With an External Accessory

Resources