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

查看:391
本文介绍了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:

  • barButtonItem
  • sourceView
  • sourceRect

为了指定锚点,您需要获取对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天全站免登陆