ios – UIActivityViewController崩溃,NSCFConstantString _beforeActivity无法识别的选择器发送到实例

前端之家收集整理的这篇文章主要介绍了ios – UIActivityViewController崩溃,NSCFConstantString _beforeActivity无法识别的选择器发送到实例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用UIActivityViewController将新的iOS 6共享功能添加到我的应用程序中.我有一些我要分享文字,如果他们选择电子邮件,我想自动设置电子邮件主题.
NSArray *activityItems = @[resultString];
NSLog(@"items=%@",activityItems);

NSArray *acitivities = @[UIActivityTypeMail,UIActivityTypeMessage,UIActivityTypePrint,UIActivityTypePostToFacebook,UIActivityTypeCopyToPasteboard];

UIActivityViewController *activityController =
    [[UIActivityViewController alloc] initWithActivityItems:activityItems
                                      applicationActivities:activities];

if (UI_USER_INTERFACE_IdioM() == UIUserInterfaceIdiomPad) {
    self.popover = [[UIPopoverController alloc] initWithContentViewController:activityController];
    // the line above is where the error happens.
    [self.popover presentPopoverFromBarButtonItem:self.emailResultsButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
} else {
    [self presentViewController:activityController
                       animated:YES
                     completion:nil];
}

以下是代码输出,包括错误消息:

[694:907] items=(
    "Lorem ipsum dolor sit amet,consectetur adipiscing elit. Maecenas porttitor accumsan mi eu mollis. Fusce condimentum dictum lectus,eu ultrices urna vulputate eu."
)
[694:907] -[__NSCFConstantString _beforeActivity]: unrecognized selector sent to instance 0x3ad971c8
[694:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException',reason: '-[__NSCFConstantString _beforeActivity]: unrecognized selector sent to instance 0x3ad971c8'
*** First throw call stack:
(0x35add2a3 0x37a1497f 0x35ae0e07 0x35adf531 0x35a36f68 0x361dc7a3 0x361dc52d 0x36067595 0x36434d31 0x3642fe07 0x2990b 0x361330ad 0x36133135 0x361330ad 0x3613305f 0x3613303d 0x361328f3 0x36132de9 0x3605b5f9 0x36048809 0x36048123 0x37bd15a3 0x37bd11d3 0x35ab2173 0x35ab2117 0x35ab0f99 0x35a23ebd 0x35a23d49 0x37bd02eb 0x3609c301 0x1ef9d 0x1ef30)
libc++abi.dylib: terminate called throwing an exception

我在带有iOS6的iPad 2上运行它.有任何想法吗?

编辑:如果我不提供活动数组似乎一切似乎工作正常.仍在缩小问题范围.

解决方法

异常说明了一切:你传递了一个字符串数组:
NSArray *acitivities = @[UIActivityTypeMail,UIActivityTypeCopyToPasteboard];

文档说该方法需要一个UIActivity对象列表:

applicationActivities

An array of UIActivity objects representing the custom services that your application supports. This parameter may be nil.

@H_502_27@

请注意,这适用于自定义活动;例如如果您想提供自己的DropBox集成以及现有服务.

编辑:至于活动类型,它们似乎只在UIActivity.activityType,UIActivityItemProvider.activityType,UIActivityViewController.excludedActivityTypes和 – [UIActivityItemSource activityViewController:itemForActivityType:]中使用.

原文链接:https://www.f2er.com/iOS/332766.html

猜你在找的iOS相关文章