Dickson Leonard Dickson Leonard - 3 months ago 46
iOS Question

UIActivityViewController crashes when presented on device

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 :

* 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

Here's the code I use

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

UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion: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


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

activityVC.excludedActivityTypes = @[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