如何在 UIActivityViewController 中添加自定义条目 [英] how to add a custom entry in UIActivityViewController

查看:38
本文介绍了如何在 UIActivityViewController 中添加自定义条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从 iPhone 或 iPad 邮件应用程序打开附件时,有一个弹出窗口可以将文件传输到第三方应用程序.

When i open an attachment from iPhone or iPad mail application, there is a popup that can transfert the file to a third party application.

此 iOS 弹出窗口称为 UIActivityViewController.

This iOS popup is called UIActivityViewController.

我想在这个弹出窗口中添加我自己的 iOS 应用程序(用 swift 编写),但我不知道该怎么做...

I wand to add my own iOS application (written in swift) in this popup and i do not know how to do...

谢谢

推荐答案

我相信你在问两个不同的事情.

I believe you are asking about two separate things.

UIActivityViewController:

这是我的应用程序中的代码.

Here's my code in my app.

let vc = UIActivityViewController(activityItems: [shareImage], applicationActivities: [])
vc.excludedActivityTypes =  [
    UIActivityType.airDrop,
    UIActivityType.assignToContact,
    UIActivityType.addToReadingList,
    //UIActivityType.copyToPasteboard,
    //UIActivityType.mail,
    //UIActivityType.message,
    //UIActivityType.openInIBooks,
    //UIActivityType.postToFacebook,
    //UIActivityType.postToFlickr,
    UIActivityType.postToTencentWeibo,
    //UIActivityType.postToTwitter,
    UIActivityType.postToVimeo,
    UIActivityType.postToWeibo,
    UIActivityType.print,
    //UIActivityType.saveToCameraRoll
]
present(vc,
        animated: true,
        completion: nil)
vc.popoverPresentationController?.sourceView = self.view
vc.completionWithItemsHandler = {(activity, success, items, error) in
}

注意excludedActiviyTypes 代码.我的应用程序是一个图像效果应用程序,所以我在弹出窗口中注释了我希望拥有的东西 - 微博,打印,assignToContact,阅读列表,Vimeo和腾讯微博.事情就是这样 - 我保留了完整的活动列表以供快速参考.(我从未在 ADC 上找到它并最终通过使用完整的代码获得它.)

Pay attention to the excludedActiviyTypes code. My app is an image effect app, so I commented out the things I wish to have in the popup - Weibo, print, assignToContact, ReadingList, Vimeo, and TencentWeibo. Here's the thing - I kept the full list of activities for quick reference. (I've never found it on ADC and end up getting it by using code complete.)

UIActivityType 是一个扩展结构,所以如果你想以这种方式使用它,我认为你必须(1)子类化 UIActivityViewController,(2)编写你自己的 UIActivityType 扩展,以及(3)提供使用上面未列出的服务所需的任何/所有代码.

UIActivityType is an extended struct, so if you want to go the route of using it this way I think you'll have to (1) subclass UIActivityViewController, (2) write your own extension to UIActivityType, and (3) provide any/all code needed to use a service that isn't listed above.

文档提供者是什么我想你正在寻找.要么,要么通用 - 有时也称为深层链接.(链接指向 Apple 文档以供使用.)

A Document Provider is what I think you are looking for. Either that, or Universal - sometimes called Deep - Linking. (The links are to Apple documentation for using each.)

我显然已经使用过 UIActivityiewController,但(还)还没有需要另外两个.

I've obviously used UIActivityiewController, but haven't (yet) had any need to these other two.

如果您对设置 UIActivityViewController 有任何疑问,请在评论中提出.如果其他人有办法以我描述以外的任何方式扩展"它,请告诉我,我将删除此答案.

If you have questions about setting up a UIActivityViewController, post them in the comments. If someone else has a way to "extend" it in any way other than I described, let me know and I'll remove this answer.

这篇关于如何在 UIActivityViewController 中添加自定义条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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