5

I'm finishing off an app for iOS 3.0 and up to run on the iPhone and iPod Touch. It's working fine on iOS4.0 and up, but when I backtest it on a second generation iPod Touch running iOS 3.0 the launch image shows and I'm met with the following:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSKeyedUnarchiver initForReadingWithData:]: incomprehensible archive (0x4e, 0x49, 0x42, 0x41, 0x72, 0x63, 0x68, 0x69)'
2012-01-15 09:35:53.025 MyApp[3026:207] Stack: (
    808001701,
    805397928,
    807551015,
    807550919,
    810902709,
    815043196,
    815042704,
    814682908,
    814682012,
    814970032,
    814968048,
    814966908,
    839149932,
    807750263,
    807747947,
    814678868,
    814672532,
    61527,
    10764
)
terminate called after throwing an instance of 'NSException'
(gdb) backtrace
#0  0x31dd594c in __kill ()
#1  0x31dd5940 in kill ()
#2  0x31dd5934 in raise ()
#3  0x31deccfe in abort ()
#4  0x374ef848 in __gnu_cxx::__verbose_terminate_handler ()
#5  0x300166c0 in _objc_terminate ()
#6  0x374ecf3c in __cxxabiv1::__terminate ()
#7  0x374ecfb4 in std::terminate ()
#8  0x374ed0dc in __cxa_throw ()
#9  0x300165e4 in objc_exception_throw ()
#10 0x30224026 in +[NSException raise:format:arguments:] ()
#11 0x30223fc6 in +[NSException raise:format:] ()
#12 0x305564b4 in -[NSKeyedUnarchiver initForReadingWithData:] ()
#13 0x3094927c in -[UINib instantiateWithOptions:owner:loadingResourcesFromBundle:] ()
#14 0x30949090 in -[NSBundle(NSBundleAdditions) loadNibNamed:owner:options:] ()
#15 0x308f131c in -[UIApplication _loadMainNibFile] ()
#16 0x308f0f9c in -[UIApplication _runWithURL:sourceBundleID:] ()
#17 0x309374b0 in -[UIApplication handleEvent:withNewEvent:] ()
#18 0x30936cf0 in -[UIApplication sendEvent:] ()
#19 0x3093687c in _UIApplicationHandleEvent ()
#20 0x3204696c in PurpleEventCallback ()
#21 0x30254a76 in CFRunLoopRunSpecific ()
#22 0x3025416a in CFRunLoopRunInMode ()
#23 0x308f0354 in -[UIApplication _run] ()
#24 0x308eea94 in UIApplicationMain ()
#25 0x0000f056 in main (argc=1, argv=0x2ffff7c8) at ...... Classes/main.m:16
Current language:  auto; currently objective-c

Any ideas what this is and how to fix it?

I'm building in Xcode 4.2.1.

PS - The problem is not resolved by cleaning the build or by resaving .xib files. Sometimes the app will get past this stage but will crash for apparently the same reason when it sees a later .xib, say in loading a view controller.

Ken
  • 30,811
  • 34
  • 116
  • 155
  • As you say you have tried cleaning the build and resaving the nib-files, I assume you have also tried resetting contents and settings in the simulator? – Emil Jan 15 '12 at 10:14
  • No, because I'm trying to run on device. The app is running fine in the simulator (iOS 4.3 and iOS 5.0 simulators). – Ken Jan 15 '12 at 10:24
  • You don't have the 3.0-simulator? I suggest you download an older version of Xcode and try to build it there to see if that helps. – Emil Jan 15 '12 at 10:27
  • I'm running Lion. Xcode 3.0 (which I have) does not run on Lion. – Ken Jan 15 '12 at 10:31
  • I suspect it might be a problem building for armv6, which I have to support, rather than for a particular version of iOS. – Ken Jan 15 '12 at 10:38
  • 1
    Have you made your XIBs in the Xcode 3.2 format? – ikuramedia Jan 15 '12 at 10:41
  • Have you deleted the app from the device and then tried again? Xcode does not delete old/removed resources on the device which can be a source for trouble. – DarkDust Jan 15 '12 at 10:42
  • @ikuragames: My xibs are made in Xcode 4.2.1. Their xml is headed: "". How would I convert the format by hand? – Ken Jan 15 '12 at 10:42
  • @DarkDust: Yes I've tried this. – Ken Jan 15 '12 at 10:43
  • 1
    I'm not 100% sure as I'm away from my computer right now, but I believe you can change the version in the right-hand side of Xcode when you have the Xib selected in the file view - I'm not sure if changing this will resave your existing Xib in the older format or if you need to recreate it... I hope it's the former. – ikuramedia Jan 15 '12 at 10:51
  • @Ikuragames: Correct. I've created an answer for this only because you're far from your computer and this question has generated some interest and upvotes. If you wish to post your own answer, even if there's some overlap, I'll up vote and accept yours. – Ken Jan 15 '12 at 14:09

1 Answers1

2

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

Ken
  • 30,811
  • 34
  • 116
  • 155
  • @ikuragames: If you don't mind I can accept my own answer here (even though it's really yours!). – Ken Jan 16 '12 at 16:07
  • Tried this on Xcode 4.2 (4C199). Versioned every single xib in the project for iOS 3.0/Interface Builder 3.0. App still crashes on my iPod touch with 3.0.. "[NSKeyedUnarchiver initForReadingWithData:]: incomprehensible archive". Multiple cleans and app deletions. Would love to see a definitive solution on this since it makes xibs pretty much useless for apps targeting the older iOS versions. – dvs Feb 02 '12 at 21:13
  • Update: In my case, the app is universal (iPhone/iPad). In MainWindow-iPad.xib, the option "Full Screen at Launch" was selected but it was throwing an "Attribute Unavailable" warning, so I unchecked it. That was when I started getting incomprehensible archive crashes. Going back and enabling the option made the app run again, but I'm still scratching my head over why an iPhone version is loading iPad xibs.. – dvs Feb 02 '12 at 21:42