I am facing a very weird issue: my iPhone is restarting.
This issue occurs in a particular scenario only.
Step 1: I have a sync process in which I'm loading data for the whole app. So I'm basically doing a heavy API call by uploading 4-5 camera captured images and syncing the app data;
Step 2: After syncing, I'm pressing the iPhone home button to make the app go in background;
Step 3: I'm locking the iPhone screen(by using side button);
After a few seconds I'm seeing the apple logo and the phone seems to restart. This is not replicating when the app is connected in debug mode. I checked the debug navigator app is using only 125 MB of memory, disk and network values is 0%. Energy Impact is showing high, I'm not sure this is due to high energy impact. I'm facing this issue only on iOS 12.4.
The fact that the phone (or possibly just springboard) restarts, and not just your application means this is Apple's bug. You're not supposed to be able to crash iOS even if you try.
Finding a likely cause will be hard since the system is not behaving the way it's supposed to. The device's logs may have more information from things other than your app. This may be a system API breaking due to any number of actions from your application.
Often with this kind of thing the next OS version will fix it, but if that's not the case or it's important to track down I would try removing ways you're interaction with the system (background APIs, notifications, etc.) and see if anything fixes the issue.
If you find the problem, you may even be doing things the "correct" way according to the documentation and have to find a workaround. If you have the time you can submit a bug to Apple so the underlying issue has a better chance of being fixed.
It seems when your app is in the background and phone locked, Automatic Reference Counting (ARC) closes some connection or deallocates a resource that makes the iPhone restart. Are you closing all connections and removing all references once the upload is complete?
Phones do not spontaneously restart just because of an app’s actions. You’re having an issue with your phone, not with a program. You need to repair or replace the phone.
Related
Having perused many other questions concerning unusual app crashes without any success at solving my problem, I have decided to post this question.
I have an app that crashes at random. Some users (in test) never have crashes, others have an occasional crash. This app is installed via XCode on testers phones, straight from the development machine. The app never crashes when in use, only upon startup a day or two after installation and use.
The app is instrumented with Crashlytics, and no crashes are detected, nor are Out Of Memory warnings. No crash logs are left on the phone after this behavior.
Crashlytics works. I injected test crashes and they were properly detected.
Once the app crashes, it will not restart. The splash screens appears for an instant and then the app closes.
The app uses Core Data and I use ObjectiveRecord https://github.com/supermarin/ObjectiveRecord as the Core Data interface. There are no aborts anywhere in the code (at least none that I added/left in)
The app downloads about 1500 images (photographs) at initialization time, and whenever the photos collection is updated. The filenames are stored in Core Data, not the binary data.
As an experiment, I took the container from the same app on another phone and replaced the container on the defective phone. No difference. Replacing the container on the good phone with the container from the bad phone made no difference either.
If I reinstall the app on the target phone, without deleting the original install, all works as expected. This leads me to believe that I am not suffering from database corruption - obviously, I may be wrong, but if advice can be offered as to how to test this, I will happily accept it.
I am at my wits' end here - any advice as to what the problem might be, or how to diagnose the problem will be gratefully received.
EDIT -- The app is for IOS 9, iphone only.
I shall answer my own question. I have been distributing the app to my 4 testers using a MacBook. I only have one license, and rather than downloading it and moving it between my iMac and MacBook, I was just allowing Xcode to generate a new certificate.
This doesn't work. Ever.
It invalidated all of the copies of the app that I installed.
The moral of the story is: beware of licensing issues - even if you have a license.
and the hint was:
Aug 29 15:48:28 iPhone amfid[170] : /private/var/containers/Bundle/Application/25BE181B-C30F-41FF-87A3-88C8E63BB3B3/TEST.app/TEST not valid: 0xe8008018: The identity used to sign the executable is no longer valid.
Live and learn I guess......
I've got an app that uses Core Data that sporadically stops launching so I have to reinstall it using XCode and then it launches again like normal for a while, with all the Core Data information still preserved.
I have seen that an app often stops launching when the target of an app is too low in comparison to the device software version, however this is not so for this app and device (iPhone 6s).
Have you had such an issue before? What do you think could be causing this problem?
There are many, many, many things that could cause an app to fail to launch. You need to narrow things down and collect some data so that you can find out what the problem is and do something about it. Right now you don't even know that it's related to Core Data, you're just guessing.
For a crash on launch, look at the device console and see what messages appear when you try to launch the app and it fails. You can get the device console messages by
Connecting your device to your Mac
Opening Xcode's "Devices" window (cmd-shift-2)
Looking in the bottom half of the window
A better way to watch the console is to use the free iOS Console app.
The problem was that, as mentioned by dan in the comments, the code was being signed for a short period of time (7 days) and so I had to keep re-installing it on the iOS device to keep it working. Thus to keep the app working indefinitely a paid developer account is needed.
Also mentioned in this reddit forum:
https://www.reddit.com/r/jailbreak/comments/4hotx3/news_free_developer_account_installs_reduced_to_7/
I did a search on this but couldn't find a match, possibly due to several meanings of the phrase "load testing"... but what we are trying to do is to make sure our App (which is a medical device that MUST display updated data in a timely fashion) will process data at a required throughput, even if the iPhone gets busy -- e.g., if there are a bunch of apps open that require CPU attention.
The best test approach we can come up with is basically that... open a bunch of apps, and perhaps try to load the CPU by sending it a bunch of emails with large attachments.
But obviously that is just kind of a stab at the risk. Are there any better techniques out there, or tools? Thanks for any help.
From the perspective of your app development, you need to focus on fixing:
"What happens when data doesn't send?"
"What happens when the app gets closed by iOS for whatever reason?"
There's a million ways to create scenarios that will cause bad cases to happen. Knowing you are covered from general failure is the safest thing to rely on.
From the perspective of validating an existing app:
In past scenarios, when I haven't had control over the development of the app, I've tested these scenarios through manual exploratory testing on physical devices.
Nowadays the iPhone Simulator now provides lots of utilities so that you may not need to do this all manually. Scroll to the bottom for these answers.
Testing when the device doesn't reliably transfer data
Nontechnical way: Go on 3G and Airplane mode and toggle connectivity frequently as you use the app.
More technial way: set your phone up to proxy through your computer. Throttle the connection. Charles does this.
As you throttle the connection, use the app to do any transactions that talk to the backend.
Do they get sent correctly once you reconnect to Wi-Fi or a more stable Wireless connection?
Testing when the CPU is overloaded
Get the oldest phone that supports your highest target OS (e.g. iPhone 4S on iOS 9) and open a few games in the background.
Use your app for about 30 minutes aggressively.
By aggressively I mean, pretend to be an impatient user that taps 5 times on every button and everywhere else on the screen until you start to notice slowness.
Exploit the areas that seem to cause the slowness.
Hot spots are: animations, videos, things that cause data to go to the backend, tableviews, collection views, etc.
See what happens to the app when it crashes.
Did you get logged out?
Was any key data malformed or lost?
Using the simulator for these things
A note about using the simulator.
The simulator is a convenient way to simulate memory warnings and you can throttle your connection with Charles, or force a reboot. But the CPU will not be throttled in the same way as if you tested on a physical device.
That aside, see the below screenshots for what options are available on the simulator that might help you.
Hope this helps!
I have an app that runs in the background. This application is called to be able to update and then goes to sleep.
For some reason, it stops working after a few hours.
I have some theories but I can not find documentation about them.
iOS closes applications when there's a lack of memory.
Does anyone know the order used in this process?
Does it choose applications that have been running longer, which occupy more memory, or does it simply randomly close apps to get the needed memory?
Is there a maximum time limit that an application may be running in background?
Is there a maximum number of repeats for an NSTimer?
Does iOS close applications in the background if battery levels are reduced in order to conserve power?
If anyone can answer these questions, or provide some information about them, that would be great.
The theories are founded on the basis of report of clients.
To answer point by point (in a simplicistic way):
An app running in background which is going into out of memory condition should get killed by the operating system, but its application delegate should receive an applicationWillTerminate message.
No time limit is officially stated for background running apps.
NSTimer can only be of one kind out of two: repeating or non-repeating. You can refer to the NSTimer class reference documentation for the evidence of such aspect.
The app can't do that, by Apple policy if I can remember correctly. If the device is running low on battery, it must not intervene on open apps to extend battery duration.
For a complete description of apps background running modes you should refer to Apple Developer Documentation at this link.
It is a good starting point to understand multitasking and the correct policy to adopt if your app has to responsibly run in the background.
In the Apple Docs you can find a very analytical description of the allowed background execution modes, under which circumstances you can use each one and also some best practices to follow. If your app follows nothing of the above, then things are getting fairly arbitrary. AFAIK there is no way to know when the operating system will kill your app or do anything to prevent it.
Start by looking into the crash report with XCode Organizer. The crash report will have an exception code that shows why the application went away.
If you have a problem with the background operation, as hinted in the question and the answer from spassas, you will see the exception code 0xbad22222 in the crash report.
See the Apple doc on exception codes for more details.
My app is an emergency app. It will be used by people in emergency and disasters.
It's possible that they got stuck in situations where they just don't have the time to enter or draw their password on the lock screen, launch the app and push a button. Is it possible that my app can ask the OS to launch the app if user throw their iPhone up in the air or shake it vigorously or something else.
What I wish to achieve by this ?
I want that OS launches my app in background if the user say shake his/her iPhone vigorously. Once launched my app will make a network request and keep running in background for short time.
PS:I think it's possible with the accelerometer.
Accelerometer will not work because Apple doesn't allow background processes opening apps. In your case, user must be opening the app by himself/herself manually. (PS. As far as I know, it's possible in Android)
iOS background tasking problems aside:
Apple don't allow apps that encourage the user to do things that might damage their iOS device. So your 'throw in the air' idea is out.
As for shaking the device -- this just isn't practical. What if the device gets shaken by accident? You've then got false alarms to deal with.
The crux of the issue is that something that triggers an emergency response should be a deliberate action which is hard to do trigger by accident.
This cannot work - and here's why.
Your app would need to run in background to handle motion events. Apps running in background can get killed at any time, i.e. if memory gets low. There might be some restrictions about running and and resource usage as well.
An app in the background cannot bring itself to the front.
Launching from a locked screen would bring great security risks.
Throwing into the air seems like a gesture that can easily be triggered by accident.
I must admit that I'm pretty happy that those apps are not allowed on the AppStore - as it would open many doors that I'd like to see kept close.