4

Trying to build and debug a universal app for iOS 3.0 using Xcode 4.3.2. I'm getting a NSException from NSKeyedUnarchiver. It seems it may be related to inability to read the main .xib file. I have seen this: iOS and unarchiving xib files -- however, in that case it's not clear the app is Universal (their solution doesn't work) (NOTE: Their solution doesn't work because they're using Xcode 4.2, not 4.3).

Here's the error output:

2000-01-01 11:00:39.-19 myApp[664:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSKeyedUnarchiver initForReadingWithData:]: incomprehensible archive (0x4e, 0x49, 0x42, 0x41, 0x72, 0x63, 0x68, 0x69)'
2000-01-01 11:00:39.-01 myApp[664:207] Stack: (
        808001701,
        805397928,
        807551015,
        807550919,
        810902709,
        815043196,
        815042704,
        814682908,
        814682012,
        814970032,
        814968048,
        814966908,
        839149932,
        807750263,
        807747947,
        814678868,
        814672532,
        12253,
        12124
    )
    terminate called after throwing an instance of 'NSException'
    Not safe to look up objc runtime data. 
4
  • So just to be clear, you HAVE set all your XIB files to the settings indicated in that answer?
    – borrrden
    Apr 1, 2012 at 5:02
  • I don't know if you have to- but I did set both the Deployment and Development to 3.0 for each of the files. I also tried settings just the iPad .xibs to 3.2. Regardless, I get the error above when debugging on iOS 3.0.
    – windup
    Apr 1, 2012 at 5:27
  • 3.2 is still bigger than 3.0. If that is the lowest it can go then you might have to consider downgrading XCode to 4.2.1 to be able to match the settings shown in that answer. If you don't want to downgrade then you have to consider raising your minimum iOS version, I guess.
    – borrrden
    Apr 1, 2012 at 6:36
  • You're misunderstanding- I set all the .xibs to 3.0 for Deployment and Development. I also tried setting only the iPad .xibs to 3.2 (as that was the first iPad capable OS). Neither of these worked.
    – windup
    Apr 1, 2012 at 7:14

3 Answers 3

3

Just thought I'd share my solution to this NSKeyedUnarchiver incomprehensible archive xib error.

I've just spent a couple of weeks pulling my hair out on this, and my workaround is pretty much the same as borrrden's, above (i.e. use nib files built with an old version of Xcode). I tried everything else I could think of without any joy. (My other choices were to stop using xib file and write the entire UI in code or to stop supporting iOS 3.0)

So, here is my situation, how I got the workaround to work and how I went about building a Distribution Archive for the app store.

First a wee bit of background: My app was originally built with Xcode 3.2.5 and worked fine on iOS 3.0 and above. When I upgraded to Xcode 4.2 I got the NSKeyedUnarchiver error as soon as the app loaded a xib file. After a bit of Googling I came across the other articles mentioned in this thread, so I changed the Deployment and Development versioning on each xib file. This worked a treat, until I upgraded to Xcode 4.3.1 when the error returned. I re-checked all the xib files but no joy. Even though they were set for iOS3.0/IB3.0 (and I tried every combination available), the app still crashed.

In an attempt to prove this was a problem with the xib files I tried debugging on device (a 2nd generation iPod Touch running iOS 3.0, attached to Xcode by cable). But the app would crash before the debugger could get going. So I removed MainWindow.xib from the project (setting the App Delegate and UIWindow up in code). This allowed the debugger to get started and hit my first breakpoint (the first line of application:didFinishLaunchingWithOptions), but the app would just hang without throwing an exception as soon I pushed a ViewController. After much digging I switched the debugger from LLDB to GDB (from Products -> Edit Scheme). This stopped the app from hanging and threw the exception as I expected it should (the incomprehensible archive one). LLDB obviously still has issues.

After a couple of weeks of pulling my hair out the only thing that worked was to use nib files built with an old version of Xcode. Luckily I still have Xcode 3.2.5 sitting on my machine. Here are the steps I used to get this working, and to allow an Archive to be built for the app store:

  • Quit Xcode 4.3.1 and start Xcode 3.2.5.
  • Create a new View-Based-Application project and add all the .xib files from your main project into it.
  • Set deployment target to iOS3.0 then do a Release Build and Run on device (use your generic provisioning profile if it doesn't pick this up automatically)
  • From Xcode, Reveal the .app in finder, then Show Package Contents to see all the .nib files within it (Xcode has converted the .xib files into .nib files).
  • For ease of use, copy the .nib files to another directory.
  • Quit Xcode 3.2.5 and start Xcode 4.3.1 and open your project.
  • Visit each xib and from the sidebar on the right deselect your app from the Target Membership (this means Xcode will not use these .xib files for the final package).
  • Now add all the new .nib files (as generated by Xcode 3.2.5) to your project (for neatness put them in a Group of their own).
  • Now you can Clean, Build and Run as much as you like and even build an Archive for the app store.

To prove the correct .nib files are being used, use md5 from the Terminal. Show your .app (or the Archive from Organiser) in Finder to see where Xcode created it then Show Package Contents to see the .nib files. Compare the md5 checksums with those from the .nib files created by Xcode 3.2.5.

Just remember that any time you modify a xib it wont get used until you build from Xcode 3.2.5. and copy the resulting .nib file to your holding directory.

This isn't ideal and if anyone has a better solution that works I'll be keen to hear it. In the meantime I hope this helps.

3
  • Thanks- wish I saw this last week. I tried what I had, as-is, on 3.1.2+ and it worked, so ended up setting my target to 3.1 instead. I actually was going to try something like what you wrote, but the old Xcode I had wouldn't run on Lion, so I gave up. Did you have any issue running Xcode 3.2.5 on Lion?
    – windup
    Apr 10, 2012 at 0:03
  • Xcode 3.2.5 on Lion worked fine for me, but you are limited to the iOS4 SDK, otherwise I'd have stuck with it. I was going down your route at one point too, but I had problems getting iOS 3.1.2 onto the device, so I gave up. Do you know if Apple have these old firmwares available for download?
    – AW101
    Apr 10, 2012 at 20:25
  • Getting 3.1.2 on there was painful- post a new question and I'll answer, so I can close this. Paste the link as a comment here.
    – windup
    Apr 12, 2012 at 20:03
0

I think I got it. iOS prior to 3.2 doesn't support the XIB format, so you need to convert it to the old NIB format first, as in this answer: Loading main XIB makes app crash on iOS 3.0

Here is the article that the question refers to iOS 3.2 SDK Release Notes

6
  • I looked at the section of the Release Notes entitled "Interface Builder". It points out two build setting "Flatten.." and "Strip". In Xcode 4.3 I see the Flatten settings, but this is already yes. I don't see a Strip settings, but would assume if it was there it would be yes as I'm not using any localization. Am I missing something?
    – windup
    Apr 2, 2012 at 1:23
  • You DON'T want to flatten it, that's the problem :D.
    – borrrden
    Apr 2, 2012 at 1:29
  • The way I read it the ability to leave the xib unflattened and unstripped was new in 3.2, but the default is to flatten and strip as had been done prior to 3.2. Regardless, I tried setting the Flatten option to NO, and instead of the error above, I get : Failed to load NSMainNibFile MainWindow_Phone.
    – windup
    Apr 2, 2012 at 2:01
  • That error message is not very helpful :-S...I assume you tried cleaning and reinstalling the project? Is there any other info you can find besides that message?
    – borrrden
    Apr 2, 2012 at 2:32
  • Unfortunately, no- this is all I get. Yes, cleaning and reinstalling. Are you able to get Xcode 4.3 to run code on iOS 3.0?
    – windup
    Apr 2, 2012 at 6:26
0

Check out this links:

SOLUTION-1:

iOS and unarchiving xib files

Read SK9's answer in above link, which is as follows:

This answer I believe covers what Ikuragames might have given (he's not near his computer). On his behalf, to solve the problem in Xcode 4.2.1 click on the .xib file and in the file properties panel on the right hand side, set the deployment to "iOS 3.0" (in my case) and development to "Interface Builder 3.0" (again in my case). Do this for every single .xib file in the project.

It's worth keeping in mind that Xcode 4.2.1 might well set defaults of "iOS 5.0" for the deployment here, to match the current SDK, and "Xcode 4.1" for the document type. Why Xcode doesn't just match the deployment target with the project deployment target I'm not sure...

If this still doesn't work or you're very paranoid by this stage, catch the exception raised by the NSKeyedUnarchiver when loading the .xib file and there create the view programmatically.

enter image description here

SOLUTION-2:

Not safe to lookup objc runtime data

Read BadPirate's answer in above link, which is as follows:

Could be that there is a malloc going on in a parallel thread. Check out this guys solution: http://www.fatcatsoftware.com/blog/2010/04

SOLUTION-3:

iPhone Simulator chrashes in NSKeyedUnarchiver after setting base SDK

Read Florian's answer in above link, which is as follows:

I solved the problem with this detailed stack trace:

#0  0x302ac924 in ___TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION___  
#1  0x904a3509 in objc_exception_throw  
#2  0x3028e5fb in +[NSException raise:format:arguments:]  
#3  0x3028e55a in +[NSException raise:format:]  
#4  0x30513b77 in -[NSKeyedUnarchiver initForReadingWithData:]  
#5  0x30ab4b2a in -[UINib instantiateWithOptions:owner:loadingResourcesFromBundle:]  
#6  0x30ab6eb3 in -[NSBundle(NSBundleAdditions) loadNibNamed:owner:options:]  
#7  0x308f85f1 in -[UIApplication _loadMainNibFile]  
#8  0x30901a15 in -[UIApplication _runWithURL:sourceBundleID:]  
#9  0x308fef33 in -[UIApplication handleEvent:withNewEvent:]  
#10 0x308fad82 in -[UIApplication sendEvent:]  
#11 0x309013e1 in _UIApplicationHandleEvent  
#12 0x32046375 in PurpleEventCallback  
#13 0x30245560 in CFRunLoopRunSpecific  
#14 0x30244628 in CFRunLoopRunInMode  
#15 0x308f930d in -[UIApplication _run]  
#16 0x309021ee in UIApplicationMain  
#17 0x0000255c in main at main.m:14   

The app crashes while calling the mainNibFile. And I don't know why, but simply re-saving the MainWindow.xib solved the problem.

Let me know if you need more help.

This solutions should help you.

4
  • I have posted links, and copied the accepted answer's from the links, just to make sure my answer doesn't become useless if this links go off due to some reason. I have given credit to the original posters by adding their name in bold. Apr 1, 2012 at 17:09
  • Parth, thanks for looking into this. The first link is the same one I mentioned in my question. The last one I saw, also, but later in the comments that commenter retracted his statement that it works. Regardless, I did try to load and resave, but no help. Are you able to get Xcode 4.3 to run an app on iOS3.0?
    – windup
    Apr 2, 2012 at 6:28
  • @windup: In my first SOLUTION-1 you need to change Deployment from interface builder to iOS 3.2. I think this should help you. Apr 2, 2012 at 7:06
  • I already tried setting both Development and Deployment to 3.0. I also tried setting the iPad .xibs to 3.2 for both Development and Deployment. You're suggesting setting all .xibs to 3.2 for Development and Deployment, even though my target SDK is 3.0?
    – windup
    Apr 2, 2012 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.