在较早的osx版本中,从xcassets加载带有imageNamed的NSImage会崩溃 [英] Loading NSImage with imageNamed from xcassets crash in older osx versions

查看:45
本文介绍了在较早的osx版本中,从xcassets加载带有imageNamed的NSImage会崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有一个xcassets,在许多应用程序之间共享.我正在装有MacOs Sierra的Mac Mini中使用Xcode8进行开发.如果我在开发机器中编译并运行,那根本没有问题.但是,当我尝试在装有OSX Mavericks的设备中运行它时,出现崩溃.这是报告中的痕迹

 线程0崩溃::调度队列:com.apple.main-thread0 libsystem_kernel.dylib 0x00007fff887dc866 __pthread_kill + 101个libsystem_pthread.dylib 0x00007fff87a3935c pthread_kill + 922 libsystem_c.dylib 0x00007fff88614bba中止+ 1253 libsystem_c.dylib 0x00007fff885dea5f __assert_rtn + 3214 com.apple.coreui 0x00007fff875aa1a7 CUIRenditionKeySetValueForAttribute + 3075 com.apple.coreui 0x00007fff875a9004-[CUIStructuredThemeStore _canGetRenditionWithKey:isFPO:lookForSubstitutions:] + 2006 com.apple.coreui 0x00007fff875a8f1b-[CUIStructuredThemeStore canGetRenditionWithKey:] + 227 com.apple.coreui 0x00007fff875c4eab-[CUICatalog _resolvedRenditionKeyForName:scaleFactor:deviceIdiom:deviceSubtype:] + 2918 com.apple.coreui 0x00007fff875c4c53-[CUICatalog imageWithName:scaleFactor:deviceIdiom:deviceSubtype:] + 299 com.apple.AppKit 0x00007fff88820b1b + [NSImage _catalogImageWithName:bundle:] + 13210 com.apple.AppKit 0x00007fff8881aefd + [NSImage imageNamed:] + 261 

如果我从xcassets中删除图像并将其单独"包含在应用程序的捆绑软件中-通过将其拖放到应用程序的项目导航器中,就可以正常加载.但是我想尽可能避免这种情况,因为在一个xcassets中共享图像更加干净.

有什么想法或想法吗?预先感谢.

解决方案

我可以按照

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.

解决方案

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:

这篇关于在较早的osx版本中,从xcassets加载带有imageNamed的NSImage会崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆