2

See Update at the bottom.

I have an iOS app written in Swift with Xcode 6.2. It defines a custom URL scheme in info.plist, and, when the app is running in the background, I can successfully open the app from within Safari, touching a link for my custom scheme. It enters here:

func application(application: UIApplication, openURL url2: NSURL?, sourceApplication: String?, annotation: AnyObject?) -> Bool { ... }

and all that works.

To try the same thing when the app is not running in the background, I double-clicked home and swiped up to remove my app from the list of running apps. When the app is not running in the background, when I touch the same link in Safari, the phone locks up. In iOS8, the screen shows Safari, but stops responding to touches. In iOS7, the screen animates to show the launch screen of my app, and then the phone locks up, not responding to touches. In either OS, the home and power buttons don't work unless I hard reset the phone. But, in either OS, if I hit run on Xcode on my desktop to launch a new instance of my app (the phone is connected with USB) then instantly the phone springs back to life and works normally.

At a loss to understand this, I put in a logger method that writes a log to NSUserDefaults.standardUserDefaults(). I can see that nonvolatile log next time I run the app. I call that logger as the first statement in the function above and also in

func application(application: UIApplication, willFinishLaunchingWithOptions launchOptions: AnyObject?) -> Bool { ... }

and when the phone locks up neither of those routines has ever been called.

I never have any problems launching the app from Xcode or just as a normal app - it's in testflight beta on the app store now. Only when launching from a custom URL, and then only when the app is not running in the background. I looked at App crashes when not backgrounded and opened using URL Scheme and application openURL in Swift and Custom URL Scheme for iOS App when not backgrounding but my app doesn't crash, it doesn't even start. And how can it lock up the phone?

I tried using the technique suggested at Subclass UIApplication with Swift to execute custom code at program start in a file called main.swift:

import Foundation
import UIKit
Globals.logNV("About to run UIApplicationMain") // log to NSUserDefaults
UIApplicationMain(C_ARGC, C_ARGV, NSStringFromClass(EWApplication), NSStringFromClass(AppDelegate)) // Subclass UIApplication

and on normal program launch that works fine, I get the message into my nonvolatile log. But when the phone locks up, when I try to launch from a URL with the app not running, then not even that message gets into the log.

I wondered if this might be a bug in how iOS handles Info.plist, so I changed the order of things there. Magically, the program now worked perfectly! But this is not repeatable. I can make a (theoretically harmless) change to Info.plist that causes the program not to run from a link, then unmake the change so the file is exactly as it was before, and still have the program not run. Something in the build causes iOS to lock up trying to launch the program, but it doesn't seem to be something I can control. I tried changing CFBundleURLName to something unrelated, and I used a different custom URL in CFBundleURLSchemes. No joy, still most builds fail. In all my tests, for one build of a program, the results are the same on iOS7/iPhone4 and iOS8/iPhone5.

  • How can I find out what iOS is doing?
  • What can I have done to my app to make it lock up the phone?
  • Any suggestions as to how to debug this?
  • Thanks!

Update

After much fooling about, it seems this may be an artefact of downloading the app direct from Xcode to the phone. If Xcode loads the app onto the phone, then, whether or not Xcode is actually connected to the phone, some app builds lock the phone up at launch from an external URL when the app is not already running. If the identical source code is built and sent to iTunes for a beta test and downloaded onto the phone with Testflight, then the bug doesn't appear. I have two different builds that behave like this now. I'm not sure this is universal but it doesn't seem implausible at the moment.

Community
  • 1
  • 1
emrys57
  • 6,679
  • 3
  • 39
  • 49

0 Answers0