【问题标题】:iPhone app won't run on iPadiPhone 应用程序无法在 iPad 上运行
【发布时间】:2015-02-12 19:28:05
【问题描述】:

在 iPad 上运行仅限 iPhone 的应用程序时遇到了问题。崩溃日志中的错误是

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_PROTECTION_FAILURE at 0x00ac3ff8
Triggered by Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_malloc.dylib          0x38cccdd4 allocate_pages + 352
1   libsystem_malloc.dylib          0x38cccace large_malloc + 70
2   libsystem_malloc.dylib          0x38cc83ee szone_malloc_should_clear + 1362
3   libsystem_malloc.dylib          0x38cc7e68 malloc_zone_malloc + 88
4   CoreFoundation                  0x2aa24ea2 __CFStringChangeSizeMultiple + 866
5   CoreFoundation                  0x2a983554 CFStringCreateMutableCopy + 408
6   CoreFoundation                  0x2a99abba -[__NSCFString mutableCopyWithZone:] + 22
7   MyApp                       0x006a274c 0xa3000 + 6289228
8   MyApp                       0x006a2a7e 0xa3000 + 6290046
9   MyApp                       0x006a2800 0xa3000 + 6289408
10  MyApp                       0x006a2a7e 0xa3000 + 6290046
11  MyApp                       0x006a2800 0xa3000 + 6289408
12  MyApp                       0x006a2a7e 0xa3000 + 6290046
13  MyApp                       0x006a2800 0xa3000 + 6289408
14  MyApp                       0x006a2a7e 0xa3000 + 6290046
15  MyApp                       0x006a2800 0xa3000 + 6289408
16  MyApp                       0x006a2a7e 0xa3000 + 6290046
17  MyApp                       0x006a2800 0xa3000 + 6289408
18  MyApp                       0x006a2a7e 0xa3000 + 6290046
19  MyApp                       0x006a2800 0xa3000 + 6289408
20  MyApp                       0x006a2a7e 0xa3000 + 6290046
21  MyApp                       0x006a2800 0xa3000 + 6289408
22  MyApp                       0x006a2a7e 0xa3000 + 6290046
23  MyApp                       0x006a2800 0xa3000 + 6289408
24  MyApp                       0x006a2a7e 0xa3000 + 6290046

在 XCode 中,由 '[UIImage imageNamed]' 导致的崩溃。这让我很困惑。我想知道如何调试和修复这种错误

更新:

断点停在这行代码

- (UIButton *)customBackButton
{
UIImage *buttonImage = [UIImage imageNamed:@"actionbar_back_nor.png"];
    UIImage *buttonImagePressed = [UIImage imageNamed:@"actionbar_back_pre.png"];
    UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [aButton setImage:buttonImage forState:UIControlStateNormal];
    [aButton setImage:buttonImagePressed forState:UIControlStateHighlighted];
    aButton.frame = CGRectMake(0.0,0.0,44,44);
    UIEdgeInsets insets;
    if (IOS_VERSION_7_OR_BETTER) {
        insets = UIEdgeInsetsMake(11, 0, 11, 22);
    }else{
        insets = UIEdgeInsetsMake(11, 11, 11, 11);
    }

    aButton.imageEdgeInsets = insets;

    [aButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
}

我将“[UIImage imageNamed:]”更改为“[UIImage imageWithContentsOfFile:]”,一切正常。为什么 '[UIImage imageNamed:]' 会导致这个错误?

【问题讨论】:

  • 如果您收到此错误,则您的应用程序将编译。您的图像是否在要复制的文件列表中?
  • 是的,我在 iPhone 上安装 32 位或 64 位都没有问题。
  • 你应该更新标题
  • @Suprie 请在[UIImage imageNamed]附近发布一些代码。
  • @AlexanderPerechnev 似乎每个“[UIImage imageNamed]”都在崩溃。如果我将其更改为 '[UIImage imageWithContentsOfFile]' 它会正常运行。

标签: ios objective-c iphone ipad


【解决方案1】:

问题是您使用无效参数将消息发送到UIImage(调用静态函数)。肯定的。

这就是您在-[__NSCFString mutableCopyWithZone:] 上收到错误的原因,因为[UIImage imageNamed:] 需要NSString 参数,但出现了错误。

所以请发布您的代码。

更新

既然你说你只为 iPhone 编译了你的应用程序并在 iPad 上运行它,我认为问题在于 iPad 上的图像查找。不幸的是,我无法更深入地了解,但根据这份文档https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/LoadingResources/ImageSoundResources/ImageSoundResources.html,我们知道 iPad 会首先查找特定于 iPad 的资源。所以我不确定,但似乎[UIImage imageNamed:] 在这一点上有些混乱。您可以尝试将您的actionbar_back_nor.pngactionbar_back_pre.png 复制到actionbar_back_nor~ipad.pngactionbar_back_pre~ipad.png

我不确定,但这似乎是唯一可以隐藏原因的地方。

但是这个问题很有趣,我会在几天后自己研究一下。因此,如果您需要更多信息,我们可以联系。

【讨论】:

  • 我已经更新了我的问题。包括imageNamed的sn-p
  • @Suprie 好吧,这个问题很奇怪。稍后我会尝试弄清楚。
  • 非常感谢先生抽出宝贵时间。我也发现这个问题很奇怪,尽管我认为这是由错误的构建设置引起的。如果我改为通用版本,它就像一个魅力。如果尝试将仅​​限 iPhone 的应用程序安装到 iPad,则会失败。
  • @Suprie 您的应用在哪一行崩溃?在这个UIImage *buttonImage = [UIImage imageNamed:@"actionbar_back_nor.png"];?
  • 是的,在那一行。如果我删除了那行代码,它将移动到其他 [UIImage imageNamed:];
【解决方案2】:

只需添加异常断点,它就会准确显示代码崩溃的位置,然后使用强大的调试器。

【讨论】:

  • 使用异常断点和调试器,只显示__lldb_unnamed_function1296$$MyApp
  • 你在堆栈跟踪中看到了什么?
  • 断点指向'[UIImage imageNamed:]'。我已经用断点指向我的代码的 sn-p 更新了问题。
  • 是的,所有图像都包含在目标中。
  • 这不是答案,而是评论。
猜你喜欢
  • 1970-01-01
  • 2014-12-04
  • 2015-03-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多