2

I have a camera app that is running fine on iOS 7. In the viewDidAppear call of my MainViewControllerI am first checking if the application state in not inactive and the application is not in background. The code sample is given below.

-(void) viewDidAppear
{
if ((UIApplicationStateBackground != [UIApplication sharedApplication].applicationState)
    && (UIApplicationStateInactive != [UIApplication sharedApplication].applicationState))
{
// check if the camera is running 
// perform  the animation of opening shutter.
}
}

My problem is that on iOS 8 beta 2 [UIApplication sharedApplication].applicationState returns UIApplicationStateInactive hence the check fails. But on iOS 7 [UIApplication sharedApplication].applicationState returns UIApplicationStateActiveand works without any problem. Has anyone else faced the same issue?

EDIT A simple experiment of putting breakpoints in viewDidAppear and appDidBecomeActive in xcode 6 reveals that viewdidAppear gets called first. I suppose its a bug in iOS 8

shshnk
  • 1,621
  • 14
  • 26

1 Answers1

4

Your view could not possibly appear unless the app was active, or at least becoming active. Views don't do things like appear when the app is inactive or in the background. So I would just delete that condition entirely if I were you. It was never serving any useful function.

(By the way, if you're encountering this situation on launch, what you're experiencing sounds like an issue that I've reported to Apple in another form: in iOS 8, the application doesn't switch to active (so that application:didBecomeActive: fires) until very late, well after the whole interface is up and running. This has caused me to have to rewrite quite a lot of my code. For example, if use my root view controller's viewDidAppear: to register for the applicationDidBecomeActive notification, I then receive that notification shortly afterwards — which is nutty.)

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • 1
    Still, I don't know yet whether Apple considers this a bug, but it sounds like you have a good test case, so you should bundle it up into a project and submit it as a bug report as well. – matt Jul 01 '14 at 04:15
  • Agree with you on the point that view appears only when the app has become active. I will modify my code to reflect the same. Please have a look at the edit in the above question. – shshnk Jul 01 '14 at 06:06
  • Yes, we're definitely talking about the same thing. This is a big change in the order of events. – matt Jul 01 '14 at 09:35
  • Hey @matt i am trying to fix exactly the same issue, i don't know how did apple respond? and how did you work around it? my issue is i have a view controller, when app comes back to active from background, i need to update some components, so i put those update codes in the UIApplicationDidBecomeActiveNotification, however, when launch app, UIApplicationDidBecomeActiveNotification method is called even later than my view did appear, so it causes a double update issue. – Xu Yin Sep 09 '14 at 02:45
  • Working around the double update at launch is easy. The problem is simply to register for UIApplicationDidBecomeActiveNotification in such a way that the notification doesn't fire immediately afterwards; the solution is to use delayed performance so that the registration takes place a couple of seconds later, _after_ the application has become active for the first time. I don't like the indeterminate nature of this solution, but how else can you register for UIApplicationDidBecomeActiveNotification if it itself is the last even you get at launch? – matt Sep 09 '14 at 14:09
  • Wow, almost 5 years later and this still seems to be an issue (I'm experiencing this on launch.. my problem is that some URL requests don't make it through, giving me an error: NSPOSIXErrorDomain Code=53 "Software caused connection abort") – Merricat Mar 17 '19 at 22:33