5

My project is Objective-C based, and have some third party swift code.

The app runs fine at debug mode, however, when I archive the app as release mode, the app will crash at launch screen.

Set swift optimization level to None still has the same issue. I have crashlytics 3.7 installed, but it crashes at launch, it didn't have a chance to upload the crash. I am very desperate. Any ideas?

Update:

I tried to remove all swift stuff and archive, everything is as usual now. However, once I drag the swift files into my Objective-C based project, Run(debug) the app is fine. But if archive(release) and install it on iPhone, immediate crash at launch. Anything what I am missing?

Wingzero
  • 9,644
  • 10
  • 39
  • 80
  • What does the device log say? – Phillip Mills Jun 16 '15 at 12:33
  • Can you post your project on GitHub? – Bannings Jun 16 '15 at 12:34
  • My app is uploaded for download, so I don't have a log. But you remind me to set the debug mode to release mode to test. Sorry I cannot post project. hold on – Wingzero Jun 16 '15 at 12:35
  • If you open Xcode's Devices window and look at the log there for your device does it say anything more interesting? – Phillip Mills Jun 16 '15 at 12:39
  • I tried to set run as release config, but Xcode only says:process launch failed: failed to get the task for process 44081. I don't find the log, there are too many – Wingzero Jun 16 '15 at 12:45
  • oops, seems Xcode does not support release mode debugging, that's why I get failed to get the task for process 44081 error. How then? – Wingzero Jun 16 '15 at 12:56
  • [update] I tried to remove all swift stuff and archive, everything is as usual now. However, once I drag the swift files into my Objective-C based project, Run(debug) the app is fine. But if archive(release) and install it on iPhone, immediate crash at launch. Anything what I am missing? – Wingzero Jun 16 '15 at 13:58

2 Answers2

4

Alright, after thousands of archiving and testing, I found it's being caused by the in-house distribution.

It is mssing one attribute 'OU' in the certificate. I had to re-create a new cert, and now it has 'OU' there. Looks like Apple does not mention it at all when dealing with old projects adopting swift code.

Quote from Enterprise Distribution not playing nice with iOS8 in Swift App

All explained in details in this article :

https://www.airsignapp.com/ios-apps-using-swift-crash-when-signed-with-inhouse-certificate/

We can confirm that after create a new cert and .mobileprovision, no more issues.

We found origins that caused this issue, related to a missing attribute in “Subject” field InHouse Certificates :

BEFORE Subject: UID=269J2W3P2L, CN=iPhone Distribution: Company Name, O=Company Name, C=FR

AFTER Subject: UID=269J2W3P2L, CN=iPhone Distribution: Company Name, OU=269J2W3P2L, O=Company Name, C=FR
Community
  • 1
  • 1
Wingzero
  • 9,644
  • 10
  • 39
  • 80
  • After spending a full day narrowing down a launch issue to the change that introduced swift into an objective c app, I finally came across this post. Xcode displayed this alert when trying to launch an enterprise distribution build, "process launch failed: timed out waiting for app to launch". This answer fixed it. Thank you. – Rob VS Dec 03 '15 at 20:23
  • Can you please share how I can check the content of the certificate. I am facing same problem even after regenerating the certificate and profile. – Surbhi Garg May 02 '18 at 10:34
  • I was desperately hoping this would resolve me issue where an objective c app now has a crashing release build after adding swift code. Unfortunately I've checked the cert using `openssl x509 -in ~/Desktop/dist.cer -inform DER -text -noout | grep Subject:` found in the link above and the OU does exist in my certificate. The search continues. – Daniel Wood Sep 06 '18 at 20:02
2

I'll post this is an answer, because I don't have the rep to post comments. I've had similar problem, although not related to Swift. Could be worth checking out though.

For me the problem had to do with file deletion in Xcode. I had removed some files from the Xcode project, but they were still present in the folder on my hard drive. When running the project through Xcode it would load these files as if they were part of the project, but when archiving it would not include them. This made the app work perfectly when run through Xcode, but crash when running the archived version, as it tried to load something that didn't exist.

So, one thing to check is that the files that should be loaded when starting the app are visible in the project navigator in Xcode. Hope it can be of help!

Anton
  • 43
  • 1
  • 9
  • I don't know if there's a way to check it automatically, but you can look through you AppDelegate and initial classes for files being loaded, and make sure that they are part of the project (either in the project navigator (cmd+1 to bring it up) or in the Copy Bundle Resources part of your Build Phases). – Anton Jun 16 '15 at 12:56
  • My app has always been working in release mode. This time I just add some swift code, and it crashes at launch. I think maybe not your case – Wingzero Jun 16 '15 at 12:59
  • Yeah, sounds like it's not the same. – Anton Jun 16 '15 at 13:01
  • Have you looked at this? http://stackoverflow.com/questions/28512096/mysterious-crashes-in-swift-1-2-in-release-builds-only?rq=1 – Anton Jun 16 '15 at 13:02
  • my view controller is in Objective-C. I am not sure if related since I have no logs... – Wingzero Jun 16 '15 at 13:07
  • You can get a crash log from the phone if you sync it in iTunes. Also, if you're lucky it might be that Crashlytics picks up the crash, but never manages to send it in time. You can try rebuilding without the swift part, and it COULD be that it'll send the error report, but I'm not sure. – Anton Jun 16 '15 at 13:12
  • Thanks for advice. crashlytics cannot send the log. it crashes too early to send. where to check the log if sync to iTunes? I don't see any – Wingzero Jun 16 '15 at 13:15
  • I believe they end up in ~/Library/Logs/CrashReporter/MobileDevice/ after you sync your device. – Anton Jun 16 '15 at 13:19
  • there are some logs, but none of them contains my app's name. any hints? – Wingzero Jun 16 '15 at 13:21
  • Try cleaning the project and uninstalling the app from the phone, and then run it from Xcode again and see if you get the same crash. – Anton Jun 16 '15 at 13:29
  • Then I'm not sure I can help you, as I haven't been using Swift myself. If you have no other way of accessing the log, you could output your messages to a file instead and look at it there. It won't give you a crash report, but it can at least give you a hint as to where it crashes. – Anton Jun 16 '15 at 13:33