gpt4 book ai didi

ios - 选择某些共享类型后如何获取 UIActivityType

转载 作者:行者123 更新时间:2023-11-28 05:51:22 27 4
gpt4 key购买 nike

我创建了一个可以共享一些文本的应用程序,但是是否有任何我可以获得的内容,无论是类型还是用户选择目的地的位置?

这里是我使用的一些代码:

let objectsToShare: [String] = [
"\(store.name) ",
store.url
]
let activityVC: UIActivityViewController = UIActivityViewController(
activityItems: objectsToShare,
applicationActivities: nil
)
self.present(activityVC, animated: true, completion: nil)

最佳答案

UIActivityViewController 上设置 completionWithItemsHandler 处理程序,然后检查 activityType...

let objectsToShare = ["\(store.name) ", store.url]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)

activityVC.completionWithItemsHandler = { activityType, completed, _, error in
guard completed else { return }

if let error = error {
// Handle error
return
}

switch activityType! { // See UIActivity.ActivityType
case .saveToCameraRoll:
//
case .copyToPasteboard:
//
case etc…
default:
// Otherwise check activityType?.rawValue
// Apple activities begin with "com.apple.UIKit.activity."
// Others use app specific values
}
}
present(activityVC, animated: true, completion: nil)

关于ios - 选择某些共享类型后如何获取 UIActivityType,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52833311/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com