activityViewController
The default implementation of this method returns
nil
. Subclasses that provide additional UI using a view controller can override this method to return that view controller. If this method returns a valid object,the system presents the returned view controller for you,instead of calling theperformActivity
method. On iPad,your view controller is presented inside of a popover. On iPhone and iPod touch,your view controller is presented modally.Your custom view controller should provide a view with your custom UI and should handle any user interactions inside those views. Upon completing the activity,do not dismiss the view controller yourself. Instead,call the
activityDidFinish:
method and let the system dismiss it for you.
请注意,第一段末尾的位置:在iPad上,您的视图控制器显示在popover内.在iPhone和iPod touch上,您的视图控制器以模态显示.
然而,在iPad上,由activityViewController返回的视图控制器总是以模态方式显示,无论我如何呈现UIActivityViewController(通过模态或通过popover).当通过popover呈现时,它会导致它崩溃,因为它不认为它被解雇.
我究竟做错了什么?这是iOS 6中的错误吗?
更新:这是一个简单的Xcode项目,说明了这个问题.随意克隆它,玩耍,看看你能不能看到我们错在哪里:github.com/simonwhitaker/GSActivityDemo
解决方法
Your app is responsible for configuring,presenting,and dismissing this view controller. Configuration for the view controller involves specifying the data objects on which the view controller should act. (You can also specify the list of custom services your app supports.) When presenting the view controller,you must do so using the appropriate means for the current device. On iPad,you must present the view controller in a popover. On iPhone and iPod touch,you must present it modally.
我把最后一行作为一个标志,你必须处理视图的呈现,所以我检查代码是否在iPad上运行,并相应地使用UIPopover.你可以在这里… https://github.com/bufferapp/buffer-uiactivity/blob/master/BufferUIActivity/Views/FirstViewController.m在以下的方法.
-(IBAction)openUIActivityView:(id)sender { NSString *text = @"Hello world"; NSString *url = @"http://bufferapp.com"; NSArray *activityItems = @[text,url]; BufferUIActivity *bufferActivity = [[BufferUIActivity alloc] init]; UIActivityViewController *activityView = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:@[ bufferActivity ]]; if (UI_USER_INTERFACE_IdioM() == UIUserInterfaceIdiomPhone) { [self presentViewController:activityView animated:YES completion:^{ }]; } else { // Change Rect to position Popover self.popup = [[UIPopoverController alloc] initWithContentViewController:activityView]; [self.popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2,self.view.frame.size.width/2,100,100) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; } }