Ad-Hoc distributed application failed to launch in time
Asked Answered
S

0

3

I have a iOS app written in Swift running on an iPad Air, with an ad-hoc distribution profile. In this version my app gets crashed by the iOS launch timer, saying it didn't launch in time. I found the explanation for this, saying I should remove heavy operations from the app delegate's didFinishLaunchingWithOptions. The weird thing is, there's hardly anything in there.

func application(application: UITimedApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Register default settings
    let appDefaults = [
        "jsonURL": "http://192.168.178.156:8888/people.json",
        "apiBaseURL": "http://192.168.178.156:8888",
        "idleTimeout": 3,
        "numberOfPeople": 2147
    ]
    NSUserDefaults.standardUserDefaults().registerDefaults(appDefaults)

    // Listen to charge state changes
    UIDevice.currentDevice().batteryMonitoringEnabled = true
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "updateDeviceTimer", name: UIDeviceBatteryStateDidChangeNotification, object: nil)
    updateDeviceTimer()

    return true
}

The only other function called in this is:

func updateDeviceTimer() {
    switch UIDevice.currentDevice().batteryState {
    case .Unknown, .Unplugged:
        UIApplication.sharedApplication().idleTimerDisabled = false
    default:
        UIApplication.sharedApplication().idleTimerDisabled = true
    }
}

The other aspect is that I used Apple Configurator to lock the iPad into using only this app. The result is that, after five crashes from the launch timer, the "guided access app unavailable please contact your administrator" message appears which means no more interaction allowed. Underneath this alert message you can see the app did eventually finish launching by the way.

The first view controller that is loaded is also very lightweight, showing some labels and a start button. The app uses Core Data, but not before the second view controller that is loaded with the start button.

I can't see why the app would take so long to launch. Is the iOS watchdog timer only looking at the return of didFinishLaunchingWithOptions method or does the stuff you do after matter also?

I tried to profile the app with Timer, but I don't really know how to read that. Plus, in debug mode, I don't have this problem at all, so Instruments are of little use.

Any ideas on how to debug this more?

This is a crash report describing the crash:

Incident Identifier: 5069F06D-B9A1-427C-B093-5118D926A3E7
CrashReporter Key:   fec3be8efd13f8877e4a696ef5cf14eba092b2cd
Hardware Model:      iPad4,1
Process:             NamesNotNumbers [146]
Path:                /private/var/mobile/Containers/Bundle/Application/28D4887C-9C3D-4E3B-9F88-C3F18E6AF409/<APP BUNDLE>/NamesNotNumbers
Identifier:          <My App bundle>
Version:             1 (1.0)
Code Type:           ARM-64 (Native)
Parent Process:      launchd [1]

Date/Time:           2015-03-23 11:13:57.770 +0100
Launch Time:         2015-03-23 11:13:35.939 +0100
OS Version:          iOS 8.1.3 (12B466)
Report Version:      105

Exception Type:  00000020
Exception Codes: 0x000000008badf00d
Highlighted Thread:  0

Application Specific Information:
<APP BUNDLE> failed to launch in time

Elapsed total CPU time (seconds): 6.260 (user 6.260, system 0.000), 14% CPU 
Elapsed application CPU time (seconds): 0.003, 0% CPU

Thread 0:
0   dyld                            0x00000001200adaa8 __fcntl + 8
1   dyld                            0x00000001200ad4b4 fcntl + 120
2   dyld                            0x000000012009b9cc ImageLoaderMachO::loadCodeSignature(linkedit_data_command const*, int, unsigned long long, ImageLoader::LinkContext const&) + 64
3   dyld                            0x000000012009e3c0 ImageLoaderMachOCompressed::instantiateFromFile(char const*, int, unsigned char const*, unsigned long long, unsigned long long, stat const&, unsigned int, unsigned int, linkedit_data_command const*, encryption_info_command const*, ImageLoader::LinkContext const&) + 228
4   dyld                            0x000000012009a9bc ImageLoaderMachO::instantiateFromFile(char const*, int, unsigned char const*, unsigned long long, unsigned long long, stat const&, ImageLoader::LinkContext const&) + 244
5   dyld                            0x000000012008f900 dyld::loadPhase6(int, stat const&, char const*, dyld::LoadContext const&) + 408
6   dyld                            0x00000001200940c8 dyld::loadPhase5stat(char const*, dyld::LoadContext const&, stat*, int*, bool*, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 168
7   dyld                            0x0000000120093f88 dyld::loadPhase5(char const*, char const*, dyld::LoadContext const&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 640
8   dyld                            0x0000000120093cd0 dyld::loadPhase4(char const*, char const*, dyld::LoadContext const&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 188
9   dyld                            0x0000000120093940 dyld::loadPhase3(char const*, char const*, dyld::LoadContext const&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 648
10  dyld                            0x0000000120093468 dyld::loadPhase1(char const*, char const*, dyld::LoadContext const&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 156
11  dyld                            0x000000012008f444 dyld::loadPhase0(char const*, char const*, dyld::LoadContext const&, std::__1::vector<char const*, std::__1::allocator<char const*> >*) + 232
12  dyld                            0x000000012008f0f8 dyld::load(char const*, dyld::LoadContext const&) + 156
13  dyld                            0x0000000120092ea4 dyld::libraryLocator(char const*, bool, char const*, ImageLoader::RPathChain const*) + 48
14  dyld                            0x000000012009866c ImageLoader::recursiveLoadLibraries(ImageLoader::LinkContext const&, bool, ImageLoader::RPathChain const&) + 336
15  dyld                            0x0000000120098354 ImageLoader::link(ImageLoader::LinkContext const&, bool, bool, bool, ImageLoader::RPathChain const&) + 104
16  dyld                            0x00000001200908e0 dyld::link(ImageLoader*, bool, bool, ImageLoader::RPathChain const&) + 180
17  dyld                            0x0000000120091718 dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) + 2244
18  dyld                            0x000000012008d040 _dyld_start + 64

No thread state (register information) available
Binary Images:
0x100050000 - 0x1000e3fff NamesNotNumbers arm64  <aac22e8e51b7365aa86fb7688118c1af> /var/mobile/Containers/Bundle/Application/28D4887C-9C3D-4E3B-9F88-C3F18E6AF409/NamesNotNumbers.app/NamesNotNumbers
0x10012c000 - 0x1002b7fff libswiftCore.dylib arm64  <5b3c2ad007c73590aabdc2554ff30d4a> /var/mobile/Containers/Bundle/Application/28D4887C-9C3D-4E3B-9F88-C3F18E6AF409/NamesNotNumbers.app/Frameworks/libswiftCore.dylib
0x100414000 - 0x10042bfff libswiftCoreGraphics.dylib arm64  <4df212c0adc635d39677885bf1eb5500> /var/mobile/Containers/Bundle/Application/28D4887C-9C3D-4E3B-9F88-C3F18E6AF409/NamesNotNumbers.app/Frameworks/libswiftCoreGraphics.dylib
0x10045c000 - 0x10045ffff libswiftCoreImage.dylib arm64  <652ee890902b3ea68b86a72cd280faa5> /var/mobile/Containers/Bundle/Application/28D4887C-9C3D-4E3B-9F88-C3F18E6AF409/NamesNotNumbers.app/Frameworks/libswiftCoreImage.dylib
0x10046c000 - 0x100473fff libswiftDarwin.dylib arm64  <6883570852443a6db73321866cb0c1c2> /var/mobile/Containers/Bundle/Application/28D4887C-9C3D-4E3B-9F88-C3F18E6AF409/NamesNotNumbers.app/Frameworks/libswiftDarwin.dylib
0x10048c000 - 0x10048ffff libswiftDispatch.dylib arm64  <cd8f8e2d57113862afda4788f098adaa> /var/mobile/Containers/Bundle/Application/28D4887C-9C3D-4E3B-9F88-C3F18E6AF409/NamesNotNumbers.app/Frameworks/libswiftDispatch.dylib
0x1004b8000 - 0x100503fff libswiftFoundation.dylib arm64  <44c6c5841e3b3c9486958cbf1a534bd4> /var/mobile/Containers/Bundle/Application/28D4887C-9C3D-4E3B-9F88-C3F18E6AF409/NamesNotNumbers.app/Frameworks/libswiftFoundation.dylib
0x100554000 - 0x10055bfff libswiftObjectiveC.dylib arm64  <252990df94bf3dc899190b1d8df925df> /var/mobile/Containers/Bundle/Application/28D4887C-9C3D-4E3B-9F88-C3F18E6AF409/NamesNotNumbers.app/Frameworks/libswiftObjectiveC.dylib
0x100578000 - 0x10057bfff libswiftSecurity.dylib arm64  <c6fd1c806cfe38cba2b21c780642b0fb> /var/mobile/Containers/Bundle/Application/28D4887C-9C3D-4E3B-9F88-C3F18E6AF409/NamesNotNumbers.app/Frameworks/libswiftSecurity.dylib
0x12008c000 - 0x1200b3fff dyld arm64  <21c893f791653e989e1c3e15446d772b> /usr/lib/dyld
0x183cfc000 - 0x183f07fff CFNetwork arm64  <68adcebf440d30769bd2d67adc7932a2> /System/Library/Frameworks/CFNetwork.framework/CFNetwork
0x18404c000 - 0x18428afff CoreData arm64  <33c0d795a45e35c9affed5cf9d83a8a1> /System/Library/Frameworks/CoreData.framework/CoreData
0x18428c000 - 0x1845e8fff CoreFoundation arm64  <83a9627362333366a8543e8c2d28166e> /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
0x1845ec000 - 0x18474efff CoreGraphics arm64  <7a02a2d0b69f3706b3cb91726db6f8af> /System/Library/Frameworks/CoreGraphics.framework/CoreGraphics
0x185190000 - 0x1853e4fff Foundation arm64  <e596bd80bcc83f15aca36a7ef014f457> /System/Library/Frameworks/Foundation.framework/Foundation
0x1884a8000 - 0x18862cfff QuartzCore arm64  <313aba56d17e30d1b68b2fdfda1820f8> /System/Library/Frameworks/QuartzCore.framework/QuartzCore
0x188b50000 - 0x1894c5fff UIKit arm64  <a1283daa6f5a33048ab9d29d91f62c09> /System/Library/Frameworks/UIKit.framework/UIKit
0x1942bc000 - 0x1942bdfff libSystem.B.dylib arm64  <882b19bba06d348d97fcdaf545163f47> /usr/lib/libSystem.B.dylib
0x194db8000 - 0x194fb4fff libobjc.A.dylib arm64  <e6224d745a023588af8e5bb67498139a> /usr/lib/libobjc.A.dylib
Slab answered 24/3, 2015 at 15:35 Comment(12)
You should get a crash log on the device that shows the stack state for your threads. A symbolicated version of that might give clues.Tonsorial
I thought this report didn't give me much information beyond "failed to launch in time". Or am I missing something? I added one of the crash reports. They are all the same I think.Slab
When I've had apps terminated for taking too much time on launch or when coming to the foreground, I've typically had a crash log that told me what was active on the main thread. (Other threads too, but not usually as important.)Tonsorial
So it's taking over 20 seconds to initialize your app and its associated library symbols (dyld). That's a new one for me...it's not even getting to your code. Are you doing anything odd in how you link the app?Tonsorial
What does that mean, how I link the app?Slab
Could it be caused by the device starting up after charging from having an empty battery and immediately having to launch the app because of Single App mode? While it's still booting other stuff in the background perhaps? My app shouldn't have to suffer from that I'd guess.Slab
The linking comment was about whether you have any custom settings in the link section of your build settings. My best suggestion at this point would be to post the question with that stack trace on the Apple Developers forum and see if anyone there knows what would cause that kind of delay.Tonsorial
Thanks! I posted it here devforums.apple.com/thread/266111Slab
Do you se cocoa pods or have a lot of embedded frameworks ?Vesture
@KostiantynKoval none! As adviced by an Apple developer on the dev forum I tried it with a blank project and the same thing happened.Slab
I'm seeing the same behavior. When it happens, my device is connected to a wifi network that doesn't have internet connectivity.Spiceberry
See my answer here: #32748461Diegodiehard

© 2022 - 2024 — McMap. All rights reserved.