简体   繁体   中英

Occasional black screen after resuming iPhone app

While testing a new build of our iPhone app, we're occasionally seeing the app window go completely black when resuming the app sometime after applicationWillEnterForeground. The only way to make the app work again is to close it completely and then restart the app. We have not been able to identify steps to consistently reproduce. This issue seems to happen at random, but only when going back into the app after it has been put in the background. Sometimes it happens after a few seconds, sometimes it won't happen for over a week.

Here are the threads in the main view during normal operation:

正常运行期间的线程

Here are the threads when this issue happens and I pause the debugger:

黑屏期间的线程

Things I've tried

Logging everything when the app resumes

Nothing appears to be out of order when the app resumes. Furthermore, none of my code is executed after applicationDidBecomeActive until the home button is pressed.

2013-05-15 22:22:23 AppDelegate::applicationDidBecomeActive
2013-05-15 22:22:23 self.window = <UIWindow: 0x1dd6ee80; frame = (0 0; 320 480); opaque = NO; autoresize = RM+BM; layer = <UIWindowLayer: 0x1dd6ef80>>
2013-05-15 22:22:23 self.window.subviews.count = 7
2013-05-15 22:22:23 self.navigationController = <UINavigationController: 0x1dd87190>
2013-05-15 22:22:23 self.navigationController.visibleViewController = <MyViewController: 0x1dd7ffe0>
2013-05-15 22:22:23 self.navigationController.view = <UILayoutContainerView: 0x1dd876e0; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x1dd877a0>>
2013-05-15 22:22:23 self.navigationController.viewControllers.count = 1
2013-05-15 22:22:23 TestFlight: App Token is recognized
2013-05-15 22:22:24 AppDelegate::applicationWillResignActive
2013-05-15 22:22:24 TestFlight: End of Session

There are a few items in the log that concerned me at first, but I have observed them during normal operation so I no longer think that they are related. Just in case, here they are:

Immediately following ApplicationWillEnterForeground:

installd[54] <Error>: 0x2ff8d000 filter_attributes: Info.plist keys requested via MobileInstallationLookup/Browse in client Xcode (via mobile_installation_proxy) were not found in MobileInstallation's cache. Please file a bug requesting that these keys be added: <CFBasicHash 0x1cd86080 [0x3c44d100]>{type = mutable set, count = 18,
entries =>
    0 : <CFString 0x3c4399f4 [0x3c44d100]>{contents = "CFBundlePackageType"}
    1 : <CFString 0x1cebf1e0 [0x3c44d100]>{contents = "BuildMachineOSBuild"}
    2 : <CFString 0x3c43aa44 [0x3c44d100]>{contents = "CFBundleResourceSpecification"}
    3 : <CFString 0x1ce90cf0 [0x3c44d100]>{contents = "DTPlatformBuild"}
    4 : <CFString 0x3c437794 [0x3c44d100]>{contents = "DTCompiler"}
    5 : <CFString 0x3c439564 [0x3c44d100]>{contents = "CFBundleSignature"}
    6 : <CFString 0x3c43a224 [0x3c44d100]>{contents = "DTSDKName"}
    7 : <CFString 0x1cebe5f0 [0x3c44d100]>{contents = "NSBundleResolvedPath"}
    8 : <CFString 0x3c436eb4 [0x3c44d100]>{contents = "UISupportedInterfaceOrientations"}
    10 : <CFString 0x3c43ee84 [0x3c44d100]>{contents = "DTXcode"}
    13 : <CFString 0x3c43eeb4 [0x3c44d100]>{contents = "CFBundleInfoDictionaryVersion"}
    16 : <CFString 0x3c43c304 [0x3c44d100]>{contents = "CFBundleSupportedPlatforms"}
    17 : <CFString 0x1ceabd10 [0x3c44d100]>{contents = "DTXcodeBuild"}
    18 : <CFString 0x1cebb610 [0x3c44d100]>{contents = "UIStatusBarTintParameters"}
    19 : <CFString 0x3c43ae54 [0x3c44d100]>{contents = "DTPlatformVersion"}
    20 : <CFString 0x3c43dbf4 [0x3c44d100]>{contents = "DTPlatformName"}
    21 : <CFString 0x3c43ec84 [0x3c44d100]>{contents = "CFBundleDevelopmentRegion"}
    22 : <CFString 0x1ceb9ae0 [0x3c44d100]>{contents = "DTSDKBuild"}
}

Shortly afterwards:

lockdownd[45] <Notice>: 2ff24000 special_case_get: MGCopyAnswer(kMGQReleaseType) returned NULL

Removing TestFlight

This is a build distributed via TestFlight, which we have used successfully for several previous releases. I have observed this behavior in a build deployed by Xcode as well, so that rules out TestFlight as a potential offender, at least in terms of the deployment. Furthermore, I have removed the TestFlight calls from the code and tested the application. After a few days, I observed the issue, so I know it's not related to TestFlight.

Verified that all NSURLConnections are performed asynchronously

Verified that all updating of the UI is performed on the main thread

The only pieces of information I really have at this point is that somehow main and UIApplicationMain are no longer on the stack. How can that happen?

Also, this app uses SDWebImage and there are UIImageViews in the displayed view when this issue happens, so maybe there's an issue there, but I really doubt that such a highly used library would have such a glaring flaw.

This occurs when the main thread is not allowed to run to refresh the UI. Possible causes:

  • Deadlock (most common in my experience)
  • Doing synchronous network calls while on a bad network connection
  • Infinite loop

I would suggest you start with checking all code that uses GCD and other threading mechanisms.

Good luck, these are very nasty problems. Sorry I can't be more to the point because the logs you showed don't ring a bell. BTW, do you only get these things in the log when the app hangs?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM