UIActivityViewController 在 iOS 8 iPad 上崩溃 [英] UIActivityViewController crashing on iOS 8 iPads

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

问题描述

我目前正在使用 Xcode 6(Beta 6)测试我的应用.UIActivityViewController 在 iPhone 设备和模拟器上运行良好,但在 iPad 模拟器和设备 (iOS 8) 上崩溃并显示以下日志

I am currently testing my app with Xcode 6 (Beta 6). UIActivityViewController works fine with iPhone devices and simulators but crashes with iPad simulators and devices (iOS 8) with following logs

Terminating app due to uncaught exception 'NSGenericException', 
reason: 'UIPopoverPresentationController 
(<_UIAlertControllerActionSheetRegularPresentationController: 0x7fc7a874bd90>) 
should have a non-nil sourceView or barButtonItem set before the presentation occurs.

我正在为 iOS 7 和 iOS 8 的 iPhone 和 iPad 使用以下代码

I am using following code for iPhone and iPad for both iOS 7 as well as iOS 8

NSData *myData = [NSData dataWithContentsOfFile:_filename];
NSArray *activityItems = [NSArray arrayWithObjects:myData, nil];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:nil applicationActivities:nil];
activityViewController.excludedActivityTypes = @[UIActivityTypeCopyToPasteboard];
[self presentViewController:activityViewController animated:YES completion:nil];

我的另一个应用程序也发生了类似的崩溃.你能指导我吗?iOS 8 中的 UIActivityViewController 有什么变化吗?我查过了,但我没有找到任何关于这个

I am getting a similar crash in of one my other app as well. Can you please guide me ? has anything changed with UIActivityViewController in iOS 8? I checked but i did not find anything on this

推荐答案

在 iPad 上,活动视图控制器将使用新的 UIPopoverPresentationController,它要求您使用以下三个属性之一为popover的呈现指定一个锚点:

On iPad the activity view controller will be displayed as a popover using the new UIPopoverPresentationController, it requires that you specify an anchor point for the presentation of the popover using one of the three following properties:

为了指定锚点,您需要获取对 UIActivityController 的 UIPopoverPresentationController 的引用并设置如下属性之一:

In order to specify the anchor point you will need to obtain a reference to the UIActivityController's UIPopoverPresentationController and set one of the properties as follows:

if ( [activityViewController respondsToSelector:@selector(popoverPresentationController)] ) { 
// iOS8
 activityViewController.popoverPresentationController.sourceView =
parentView;
 }

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

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