Two status bar in the app when application comes in foreground from background and UI freezes in iOS - ios

I am working on an iOS app in which I have to do numerous calculations in the loop which is running say 5000 times on the main thread. So its taking a little bit time before loading the UI and activity indicator is loading till then.If the app goes background and comes back to foreground the UI freezes for the time till the app completes the loop operation.
One specific thing that I found is that I am getting two status bar in the app which is overlapping each other.you can see time and battery percentage value overlapping each other (Refer Screen Shot below).This only happens when app goes to background and comes back to foreground freezing my Activity Indicator. Even though if I want to replace the activity with a new one or stop and start it again still there is no response and the UI is freezes unless the loop completes its iteration and sometimes leading to app crash as well.
If app calculation is completed (normal case) and then if app goes to back ground and comes back then every thing works smoothly.
Please suggest me whats going wrong with my app.

Related

Application starts from Home Screen if app remains in the background for more than 30 seconds instead of showing the screen when it went to background

My iOS application is kind of messaging app, so user can send audio, video, images, etc. When user typing the message and app went background for more than 30 seconds then app launches from Home screen and all that messages, everything will be lost. Before 30 seconds app launches at the exact point where it went background. So how to do that same after 30 seconds also, at least I should maintain this state for 30 minutes.
Is using background process and schedule task will be a good method here in iOS 13+?
I particularly don't want to do anything on the background but when app comes from background to foreground within 30 minutes I want to maintain that state.
Messages Disappearing
Well, first of all, why are all the messages lost? if your trying to make a snapchat like experience where the messages disappear after you see them then that's fine but otherwise it might be worth adding a local storage for these messages using CoreData.
Cause
The main issue, after a little while iOS will but an app to sleep so to say, in this scenario it will remove all temporary data within your app, this means when you re-open it it will start from the beginning, it does this to save memory.
Solution
There are a few ways to solve this, you could use State Restoration
For a beginner though this could be quite tricky as the documentation on it is quite sparse.
Another option would be to save the last screen in UserDefaults and then when the app re-launches you can use the value to push the last screen the user was on. For both these solutions though you will need a way to persist the messages and re-fetch them (a database) CoreData would probs be your best bet
I do personally think State Restoration is the best option especially since it sounds like that's exactly what you want to do:
but when app comes from background to foreground within 30 minutes I want to maintain that state.

Questions about app state after tapping on app icon after apps enters suspended state

I’m putting an app into background.
Assuming that I’m not doing anything to keep the app alive in the background, then the app goes through suspended state in a matter of 5 seconds. Right?
What happens if I then tap on the app icon? That’s not suppose to trigger a didFinishLaunch right? It will just bring me back to the last screen I was at and also trigger didbecomeActive & willenterforeground notifications. I won't be getting any other callback. Right?
Assuming there is no restart of the phone, point 2 is true even if there are hours between me tapping home and then tapping back the app icon. Right? Does it also persist device restarts but not force-restart?
The only time I won’t be brought back to the screen I was at (before hitting home) is if the device receives a memory warning and my app is flushed out of suspended state. At this point tapping on the app icon will result in didFinishLaunch. Right?
(I’m asking all of this because sometimes after putting the app in the background and tapping the app icon again (e.g. 10 minutes later), the app is going through it’s launch phase. Most of the time it just goes back to its previous screen)
I've already seen Will ios terminate the app running in background after a specific time? but that doesn't address all aspects I want.
It will just bring me back to the last screen I was at and also trigger didbecomeActive & willenterforeground notifications.
Right, if your app was not terminated in the background.
I won't be getting any other callback.
Not necessarily true. If you were summoned to the front by a local notification, for example, you'll also get an event about that.
Assuming there is no restart of the phone, point 2 is true even if there are hours between me tapping home and then tapping back the app icon.
Not necessarily. The app might well be terminated silently in the background.
Does it also persist device restarts but not force-restart?
Absolutely not. How can the app run when the device is off? Shutting down the app terminates every app.
I’m asking all of this because sometimes after putting the app in the background and tapping the app icon again (e.g. 10 minutes later), the app is going through it’s launch phase
It's not a matter of time. The watchdog process is constantly combing the suspended apps looking for the ones that take up too much memory so that other apps can run. You must not be surprised if yours is one of them.
You can come back to the front launching from scratch or by coming back to life from suspension; it's the most basic fact of iOS app life! You just need to accept it.
But there are lots of things you can do to reduce your chances of being terminated in the background. Giving up memory-consuming objects as you background is first on the list.

IOS: forcing update before app becomes visible

I have a timer in my app, and I want it to appear to be running while my app is on the background. I'd like that if the user presses the home button when the timer shows, for instant "01:11:11" and then goes back to the app and it becomes visible to him 10 minutes later, to see the timer as "01:01:11", however I get a split second where it shows the last state when the app went to the background ("01:11:11") before it starts updating from the correct time.
I assumed that I could correct this by updating the state of my timer in "applicationDidBecomeActive" and it did work on my simulator in Xcode but not on my Ipad.
I'm using cocos2d for my drawing and this is what I'm doing in my applicationDidBecomeActive:
CCScene *s=[director_ runningScene];
GameLayer *l=[(GameLayer*)[s getChildByTag:GAME_LAYER_TAG];
if (l!=nil) [l myUpdate];
I don't think it's relevant to the problem though because myUpdate does get called but I still have that split second glitch on my Ipad, as if it starts back from its last state no matter what.
In apples clock app, in applicationDidEnterBackground it hides the timer text, so that when the app comes into the foreground you see a blank UI for the split second where your app is loading the new timer data in the UI. Also, you may want to call some of your applicationDidBecomeActive code in applicationWillEnterForeground, which is called first. But keep in mind, applicationWillEnterForeground is not called when the app first launches.
There will always be a delay between when your app comes into the foreground, and when the UI updates. Theres no way to fix that, so you might as well use what apple uses to get around the issue.
Well I tried to hide my UI in both applicationWillResignActive and applicationDidEnterBackground. Since applicationWillResignActive is called first and before going into preview (double click on HOME) it causes a "not so pretty" preview but I thought at least it would solve my original problem. It didn't (not, on my IPad). It looks like the system takes the screen shot even before applicationWillResignActive.
I checked the timer in the official clock app and I see the clock is updating even when the app is in the background (in preview), so they "cheat" anyway...

iOS App Goes Dim

Very difficult issue to figure out...this only happens on a real device not plugged in. When my app loads up to the main view, i show a wait dialog while a few background threads fire off and search for products. this takes about 5-7 seconds. If I load the app and about 1-3 seconds in, i close the app and go to another app, then come back to my app, the screen dims around the edges and the app just freezes.
I did a few google searches for this screen dimming and couldn't find anything
The app never crashes.

What are causes of freezing in an iOS app after returning from background?

This is very difficult issue, since it doesn't occur every time.
When an app is just launched, returning from background, it is fine without any freezing.
After some time being in background, when I re-activate it, the whole UI is frozen for while, even the activity indicator is not animating. As time goes on, this freezing gets longer and finally causes the app to be terminated by iOS for not resuming in time.
I would like to learn what are the generic causes of an app to be unresponsive, especially if the app is supporting background running feature and re-activating after a period of being in background.
It looks like I have missed some fundamental techniques that should be respected to avoid freezing problems.
UPDATE: I am suspicious if saving UIImage into Core Data object can be the main reason. At launch, it's not visible, however, as time passes, numerous saveManagedObjectContext are performed while UIImage is still referenced.
Maybe I should have listened to the instruction not to save any image in Core Data?
check for your crash log if you are getting this
Exception Codes: 0x8badf00d
then its most probably your application is taking much time either in launch or while moving in background or terminate, actually app take much time in launch/shut iOS suspend it and our app freeze, there is no such time define in documents but as i experienced it should not be more then 4-5 seconds. check your app delegate applicationDidFinishLaunch or multitasking delegates there is some code which is taking time in completion. For more info lokk at these
http://developer.apple.com/library/ios/#technotes/tn2151/_index.html
http://en.wikipedia.org/wiki/Hexspeak

Resources