Build universal app for iOS 3.0 using Xcode 4.3.x - NSKeyedUnarchiver Exception

Deadly 提交于 2019-11-30 22:23:57

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.

borrrden

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

Parth Bhatt

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!