UIActivityViewController UIActivityViewControllerCompletionWithItemsHandler [英] UIActivityViewController UIActivityViewControllerCompletionWithItemsHandler

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

问题描述


  • 列表项目

使用Swift作为在iOS 8中运行的应用程序,我需要编写 UIActivityViewController 的完成处理程序,用于捕获用户选择的共享方法的结果。

Using Swift for an app that runs in iOS 8, I need to write a completion handler for the UIActivityViewController to capture the results of which "share" method a user selected.

这是到目前为止我的代码片段。我的问题是如何设置 avc.completionWithItemsHandler ?我确定它很简单,但我没有看到它。

This is a snippet of the code I have so far. My question is how to I set the avc.completionWithItemsHandler? I'm sure it's simple, but I don't see it.

var activityItems = NSMutableArray()
activityItems.addObject("Email or text for 'share' goes here")

var avc = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
avc.setValue("Subject for Email", forKey: "Subject")

avc.completionWithItemsHandler = //Here is where I dont know what to do.

self.navigationController?.presentViewController(avc, animated: true, completion: nil)


推荐答案

completionWithItemsHandler typealias:

The completionWithItemsHandler typealias:

typealias UIActivityViewControllerCompletionWithItemsHandler = (String?, Bool, [AnyObject]?, NSError?) -> Void

注意:以前的代码块不会在你的项目中使用,它只显示类型需要关闭(文档)。

Note: the previous code block is not to be used in your project, it just shows the type of closure needed (docs).

所以这些是传递给完成处理程序的参数,你可以这样做,所以完成处理程序看起来像这样:

So those are the parameters that are passed into the completion handler for you to do with as you will, so the completion handler would look like this:

avc.completionWithItemsHandler = { activity, success, items, error in 

}

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

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