UIActivityViewController在设备上显示时崩溃 [英] UIActivityViewController crashes when presented on device

查看:1420
本文介绍了UIActivityViewController在设备上显示时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中添加ios默认共享表/ UIActivityViewController时遇到问题。它在模拟器上工作正常,但是当它使用usb cable或testflight在设备(iPhone)上运行时崩溃。我收到的错误消息是:

I'm having trouble with adding ios default share sheet / UIActivityViewController on my project. It works fine on simulator but it crashes when it's run on device (iPhone) using either usb cable or testflight. The error message I get is :


*由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'* - [__ NSCFString rangeOfString:选择:范围:区域设置:]:无参数
***第一掷调用堆栈:
(0x182ddedb0 0x182443f80 0x182ddecf8 0x1836d2ac8 0x1928f90cc 0x1928f8394 0x187f3cc40 0x187f3c844 0x1888f5050 0x182cd6584 0x182ccd2ac 0x1888f4c9c 0x1888f5560 0x187f3cc40 0x187f3c844 0x1883b4bd8 0x18813cc78 0x187f3cc40 0x187f3c844 0x1882c4228 0x1882bd3b8 0x1882bee54 0x1882c1890 0x1880373cc 0x1001ae7b8 0x187f74be8 0x187f74b64 0x187f5c870 0x187f74454 0x187f2cc0c 0x187f6d610 0x187f6cc0c 0x187f3d04c 0x187f3b628 0x182d9509c 0x182d94b30 0x182d92830 0x182cbcc50 0x1845a4088 0x187fa6088 0x100137c88 0x18285a8b8)
的libc ++ abi.dylib:与类型NSException的未捕获的异常终止

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSCFString rangeOfString:options:range:locale:]: nil argument' *** First throw call stack: (0x182ddedb0 0x182443f80 0x182ddecf8 0x1836d2ac8 0x1928f90cc 0x1928f8394 0x187f3cc40 0x187f3c844 0x1888f5050 0x182cd6584 0x182ccd2ac 0x1888f4c9c 0x1888f5560 0x187f3cc40 0x187f3c844 0x1883b4bd8 0x18813cc78 0x187f3cc40 0x187f3c844 0x1882c4228 0x1882bd3b8 0x1882bee54 0x1882c1890 0x1880373cc 0x1001ae7b8 0x187f74be8 0x187f74b64 0x187f5c870 0x187f74454 0x187f2cc0c 0x187f6d610 0x187f6cc0c 0x187f3d04c 0x187f3b628 0x182d9509c 0x182d94b30 0x182d92830 0x182cbcc50 0x1845a4088 0x187fa6088 0x100137c88 0x18285a8b8) libc++abi.dylib: terminating with uncaught exception of type NSException

这是我使用的代码

-(void)share {
    NSString *item = @"test";
    NSArray *items = @[item];

    UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
    [self presentViewController:activityVC animated:YES completion:nil];
}

它在presentViewController行崩溃。我已经确定activityVC不是nil并且如果我尝试呈现常规视图控制器它不会崩溃。以下是崩溃前的堆栈跟踪

It crashes on the line with "presentViewController". I've made sure activityVC is not nil and it doesn't crash if I try to present regular view controller. Here are the stack trace right before it crashes.

我在一个空项目上尝试了完全相同的代码,它可以在模拟器和设备上运行,这就是我怀疑问题可能与项目/构建设置有关的原因

I tried the exact same code on an empty project and it works on both simulator and device which is why I suspect the issue might be with the project / build setting

推荐答案

原来我需要排除AirDrop才能在设备上运行。

Turns out I need to exclude AirDrop in order for it to work on device.

activityVC.excludedActivityTypes = @[UIActivityTypeAirDrop];

我不知道为什么会这样,因为我可以将AirDrop包括在其他项目中(在具有相同iOS版本的同一设备上进行测试)。可能有一些项目设置可能允许/禁止AirDrop。这个答案对我有用,因为我不需要AirDrop用于我当前的项目,但如果有人能解释为什么UIActivityTypeAirDrop仅在我的项目中崩溃,我将不胜感激

I don't know why this is the case since I can include AirDrop just fine on other projects (testing on the same device with same iOS version). Probably there's some project setting which could allow / disallow AirDrop. This answer works for me since I don't need AirDrop for my current project but I would appreciate it if someone could explain why UIActivityTypeAirDrop crashes only on my project

这篇关于UIActivityViewController在设备上显示时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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