News

Unity 3.x to Unity 4.x iOS migration

When migrating an iOS project from Unity 3.x to 4.x I found that my app crashed with an error of “unrecognized selector sent to instance” on a system class (UIDevice) that I had a category extension for in a static library. Odd.

There was nothing wrong with the code or the static library. The cause was that the default Xcode project that Unity 4.x generates differs from the the 3.x version. Under Other Linker Flags the option -all_load is missing. Add this in and everything should work again. Depending on your project, you may be able to get away with -ObjC instead.

From this Apple Technical Q&A:

Objective-C does not define linker symbols for each function (or method, in Objective-C) – instead, linker symbols are only generated for each class. If you extend a pre-existing class with categories, the linker does not know to associate the object code of the core class implementation and the category implementation. This prevents objects created in the resulting application from responding to a selector that is defined in the category.

To resolve this issue, the target linking against the static library must pass the -ObjC option to the linker. This flag causes the linker to load every object file in the library that defines an Objective-C class or category

But note at the bottom of the page this warning:

Important: For 64-bit and iPhone OS applications, there is a linker bug that prevents -ObjC from loading objects files from static libraries that contain only categories and no classes. The workaround is to use the -all_load or -force_load flags.
-all_load forces the linker to load all object files from every archive it sees, even those without Objective-C code.

Tags: , , ,

Comments are closed.

This site uses Cookies - By using this site or closing this you agree to our Cookies policy.
Accept
x