Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading NSImage with imageNamed from xcassets crash in older osx versions

So, I have an xcassets that is shared amongst quite a few apps. I'm developing with Xcode8 in a Mac Mini with MacOs Sierra installed in it. If I compile and run in the development machine, there's no issue at all. However, when I try to run it in a device with OSX Mavericks I get a crash. Here's the trace in the report

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib          0x00007fff887dc866 __pthread_kill + 10
1   libsystem_pthread.dylib         0x00007fff87a3935c pthread_kill + 92
2   libsystem_c.dylib               0x00007fff88614bba abort + 125
3   libsystem_c.dylib               0x00007fff885dea5f __assert_rtn + 321
4   com.apple.coreui                0x00007fff875aa1a7 CUIRenditionKeySetValueForAttribute + 307
5   com.apple.coreui                0x00007fff875a9004 -[CUIStructuredThemeStore _canGetRenditionWithKey:isFPO:lookForSubstitutions:] + 200
6   com.apple.coreui                0x00007fff875a8f1b -[CUIStructuredThemeStore canGetRenditionWithKey:] + 22
7   com.apple.coreui                0x00007fff875c4eab -[CUICatalog _resolvedRenditionKeyForName:scaleFactor:deviceIdiom:deviceSubtype:] + 291
8   com.apple.coreui                0x00007fff875c4c53 -[CUICatalog imageWithName:scaleFactor:deviceIdiom:deviceSubtype:] + 29
9   com.apple.AppKit                0x00007fff88820b1b +[NSImage _catalogImageWithName:bundle:] + 132
10  com.apple.AppKit                0x00007fff8881aefd +[NSImage imageNamed:] + 261

If I remove the image from the xcassets and include it "individually" in the app's bundle -by dropping it to the app's project navigator- it loads just fine. But I'd like to avoid this if possible, as it's cleaner to have shared images in just one xcassets.

Any thoughts or ideas? Thanks in advance.

like image 649
leandrodemarco Avatar asked Oct 02 '16 21:10

leandrodemarco


1 Answers

I could bypass this error by following this workaround provided by Apple for iOS 7 devices:

To work around this issue, update the deployment target to iOS 8.0 or higher, or add a single image to the asset catalog that has at least five attributes specified across the image set, such as: scale (1x, 2x, 3x) idiom (add iPad,iPhone, and a universal asset) direction (left to right, right to left) width/height class (any & compact, and so forth) memory (add a 1 GB asset) graphics (add a Metal 1v2 asset) It is not necessary to use the image in your code or to add all of these attributes. (27852391)

Here's how this dummy imageset looks like:

Dummy imageset

like image 196
leandrodemarco Avatar answered Oct 20 '22 00:10

leandrodemarco