How to stop/handle UI Operations in iOS when app moves to background state? - ios

My app can be launched via UIApplicationLaunchOptionsLocalNotificationKey in the background. In that case the usual flow to setup initail view controller and some animations on the app's landing-page/first-page of the app take place.
My question is, Is this a good practice, If I leave these animations like this even when my app is launched via OS in background? Three things I am concerned about:
Some animations are continuous, like a circular-dot(UIImage) expanding and shrinking, using CAAnimation.
Some views are added and removed as subviews to the keyWindow, based on user location.
When user taps the home button, do I need to stop the animations and subview additions then also?
Making the animation stop and resume via applicationDidEnterBackground and applicationWillEnterForeground seems tedious.

Related

When app backgrounded lock screen does not fully animate in

Background
When the app is backgrounded I want to have a lock screen that forces the user to log in again. I have implemented this in the OnResignActivation method in AppDelegate.
Functionally this works fine, however, when backgrounded the lock screen tries to slide in but doesn't have time to complete. When the app opens again this animation completes.
Question
How can I get the animation to complete or not use the animation at all so that when ever the app is opened again the lock screen is there and not half way across?
Solution
The solution was in fact in implement the lock screen logic in DidEnterBackground instead of OnResignActivation in AppDelegate.
As the code was running to soon in the life cycle I was getting half an animation behaviour. Putting it in DidEnterBackground resolves this.
These SO answers helped me arrive at this solution.
https://stackoverflow.com/a/12416131/1593273
https://stackoverflow.com/a/25985478/1593273

iOS Swift Briefly Display Info

I want to have some information drop down from the top of a view, stay on the screen for a second or two, and then go back up out of the view. I have search for displaying notifications and/or banners. All I get is either push notifications (which I don't need to use) or iAds banners.
I'm working on a barcode scanning app and I want to briefly show the value of the barcode shown without requiring the user to tap on anything. How can I accomplish this?
Don't use notifications and banners, because that might not work: the user can turn them off. In any case this is not a notification of anything, so it's a misuse of notifications.
Just do what you described, yourself: animate a view onto the screen, and then (in the animation's completion handler) use delayed performance to animate the view right back off the screen after a short delay.
You should use a view which manages its own state (INCOMING, STAY PUT, OUTGOING). This way you can reduce the memory footprint and many other bugs in the process. I coded something for a similar process. Check it out

Animation is disturbed by Multitasking

I am developing an iPhone applciation in which I am applying UIView Animation, but when multitasking occurs like user answers a call or a skype call, my animation is disturbed.
Is there any way to avoid this?
EDIT
Suppose a scenario Skype call is running, in the meanwhile i started my application that has some UIView Animation, while skype call is running its behaviour turns strange? Any comment on that ??
You can't avoid disturbance from incoming calls and other things like that. What you can do is to save the state of you animation in the moment when interruption happens and restore this exact state to continue your animation when app is back in foreground.
What usually happens is that the animation jumps to the "end point" instantly. In case you have cascading animations it's best to make sure you are not in multitasking when starting the new one.

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: Hiding sensitive information on the screen when app is backgrounded

When a foreground app gets backgrounded (e.g. Home button gets pressed), how can I change elements on the topmost view controller prior to when iOS takes a snapshot of it and starts the animation to show the next screen?
I ask because I'm writing an app requiring HIPAA compliance, and I am concerned that the snapshot that the OS takes in order to do this animation sometimes contains sensitive data which should not be visible even for a split second when the app gets foregrounded later.
I'm aware that view controllers have lifecycle methods such as viewWillDisappear which might be usable, but I have a lot of controllers and I'd rather just have something in my App Delegate to handle this (e.g. by adding an opaque full-screen UIImageView overlay) rather than having to write custom code for this in every last controller.
I tried putting overlay-generating code in applicationWillResignActive, and I've been digging with Apple's docs and Google, but it's not working. I suspect the screenshot gets taken before the app has a chance to update the screen.
Thanks!
Not sure about HIPAA's requirements about backgrounding and possibly leaving the user logged in for someone else to resume, but the safest sounds like it would be to add a key UIApplicationExitsOnSuspend with a boolean value of YES to info.plist.
That will prevent the app from backgrounding entirely, and restarts it (possibly triggering a login procedure) every time you go back to it.
Most (if not all) mobile banking applications I've tested do this for safety reasons.
I believe the answer is to not concern oneself with changing what's on the screen before the backgrounding animation begins, but to simply modify what's displayed on the screen once the app enters the background (i.e. inside of applicationDidEnterBackground: in your App Delegate.) This solved my problem.
My UIImageView overlay idea worked here, although I decided just to pop to the root view controller instead. Simpler that way. My root view doesn't have any sensitive info.
Here's what it looks like:
-(void)applicationDidEnterBackground:(UIApplication *)application {
UINavigationController *navigationController =
(UINavigationController *)self.window.rootViewController;
[navigationController popToRootViewControllerAnimated:NO];
...
}

Resources