iOS 8.3(12F70)上的ViewController presentViewController崩溃

iOS 8.3(12F70)上的ViewController presentViewController崩溃,ios,uiactivityviewcontroller,ios8.3,Ios,Uiactivityviewcontroller,Ios8.3,我为这个问题挣扎了三天: 我从SO获得的示例代码在ios7.11上运行,但在奇怪的崩溃日志中崩溃: 代码是: UIImage *image=[UIImage imageNamed:@"wishlist_active.png"]; NSString *str=@"Image form My app"; NSArray *postItems=@[str,image]; UIActivityViewController *controller = [[UIActivityViewController

我为这个问题挣扎了三天: 我从SO获得的示例代码在ios7.11上运行,但在奇怪的崩溃日志中崩溃:

代码是:

UIImage *image=[UIImage imageNamed:@"wishlist_active.png"];
NSString *str=@"Image form My app";
NSArray *postItems=@[str,image];

UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:postItems applicationActivities:nil];

//if iPhone
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    [self presentViewController:controller animated:YES completion:nil];
}
//if iPad
else {
    // Change Rect to position Popover
    UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:controller];
    [popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4, 0, 0)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
iOS 8.3上的崩溃日志为:

2015-06-22 18:09:22.706 MyApp[827:61605] *** Terminating app due to uncaught exception 'NSRangeException, reason: *** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array
***第一次抛出调用堆栈:

(0x2341afef 0x31968c8b 0x2332d821 0x27120261 0x271202b7 0x26d0aab1 0x26e03dcd 0x26e037a7 0x26a6fb8f 0x26a6f8fd 0x26c3fb0b 0x26a6fb8f 0x26a6f8fd 0x26d61677 0x26d5c949 0x26d5da83 0x26d5f5e7 0x26b4ff5f 0x143c15 0x26aa0e2b 0x26aa0dd1 0x26a8b9c3 0x26aa083d 0x26aa0517 0x26a99df1 0x26a6ffe5 0x26ce68fb 0x26a6e9f9 0x233e0faf 0x233e03bf 0x233dea25 0x2332b201 0x2332b013 0x2ac0a201 0x26acfa59 0x144c11 0x31ef4aaf)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

我已经在8.3上检查了你的代码,它运行时没有任何崩溃。 因此,我建议您将NSParametAssert;对于要检查的阵列上的项目,如果一切正常。即使这个问题是由代码的另一部分引起的,在使用文本初始化将其放入数组之前检查抛出NSParametAssert的项也是一个很好的做法

如果您使用navigation controller,请尝试从navigationController呈现Activity VC,如下所示:

 UIImage *image=[UIImage imageNamed:@"images.png"];
    NSString *str=@"Image form My app";
    NSParameterAssert(image && str);
    NSArray *postItems=@[str,image];

    UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:postItems applicationActivities:nil];

    NSParameterAssert(controller);
    //if iPhone
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        [self.navigationController presentViewController:controller animated:YES completion:nil];
    }
    //if iPad
    else {
        // Change Rect to position Popover
        UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:controller];
        [popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4, 0, 0)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    }

希望这有帮助。

您应该设置一个异常断点-当您在Xcode中时,按CMD+7将打开左侧的断点导航器。然后按左下角的+并选择添加异常断点。完成后,请在iOS8.3上再次运行代码,并显示代码实际崩溃的行,此时调试器将在该行停止。您是否使用真实设备进行测试?是的,我在真实设备上进行了测试,这似乎是8.3中的一个bug,因为它在ios 7.1.x设备上运行良好,对于断点,我添加了异常断点,它停在[self-presentViewController:controller animated:YES completion:nil];这段代码在我的8.3设备上运行良好。你从哪里调用它?这可能是因为我在一个大型项目中使用的自定义视图,以及如何跟踪不是我们的代码的崩溃,即框架原因异常断点也不能告诉崩溃发生的行,我尝试了符号断点,但失败了。如果我在示例项目上尝试,此代码可以工作,但在项目上失败了,您猜问题出在哪里?@Vigneshwaran.m尝试设置断点并检查包中是否存在image.png。另外,检查导航控制器是否存在。希望这对你有帮助。如果这篇文章对你有用,就把它标记为问题,或者投票给你