gpt4 book ai didi

ios - CKAsset (NSData) 到 UIWebView 与 ActivityViewController 共享

转载 作者:行者123 更新时间:2023-11-30 12:37:44 25 4
gpt4 key购买 nike

我有 PDF 文件作为 CKAssets,它们在 UIWebView 中被调用和呈现,没有问题。我已经设法操纵代码,以便 CKAsset 将出现在 ActivityViewController 中,但这是在 func 方法内,我希望将此部分分配给操作按钮。我的问题是如何在函数中调用几行?或者在 func 之外有足够的引用来使操作按钮起作用?

这是功能代码-

func queryRecord() {

let container = CKContainer.default()
let publicDatabase = container.publicCloudDatabase
let predicate = NSPredicate(format: "recordID = %@", CKRecordID(recordName : documentID))
let query = CKQuery(recordType: "Documents", predicate: predicate)

publicDatabase.perform(query, inZoneWith: nil, completionHandler: ({results, error in

if (error != nil) {
DispatchQueue.main.async() {
self.notifyUser("Cloud Access Error", message: error!.localizedDescription)
}

} else {
if results!.count > 0 {

let record = results![0]
print(record)

DispatchQueue.main.async() {

let docTitle = record.object(forKey: "documentName") as! String

self.title = "\(docTitle)"

let docType = record.object(forKey: "documentType") as! String

if docType == "PDF" || docType == "pdf" {


if let asset1 = record.object(forKey: "documentFile") as? CKAsset {
let doc1Data : NSData? = NSData(contentsOf:asset1.fileURL)
self.docWebView.load(doc1Data! as Data, mimeType: "application/pdf", textEncodingName: "UTF-8", baseURL: NSURL() as URL)
let filenameURL = [(asset1.fileURL)]

let activityController = UIActivityViewController(activityItems: filenameURL, applicationActivities: nil)
self.present(activityController, animated: true, completion: nil)

}

} else {

我尝试在代码外部引用 filenameURL,但它无法识别 filenameURL 不是该类的成员。

最佳答案

我想通了(我想)。这里是 -

我变了

let filenameURL = [(asset1.fileURL)]

self.filenameURL = [(asset1.fileURL)]

然后添加

var filenameURL : Any? 

到 ViewController 类。这允许我将相关代码添加到actionButton -

@IBAction func activityVCButton(_ sender: UIBarButtonItem) {
let activityController = UIActivityViewController(activityItems: (filenameURL as? [Any])!, applicationActivities: nil)
self.present(activityController, animated: true, completion: nil)
}

我认为我似乎缺少的关键是“任何?”,但如果我缺少一些更基本的东西,我很高兴得到纠正。

关于ios - CKAsset (NSData) 到 UIWebView 与 ActivityViewController 共享,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42660888/

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