如何将AVCaptureMovieFileOutput保存到iCloud

时间:2017-04-26 23:19:34

标签: swift avfoundation icloud

我创建了一个电影文件,并且能够将其本地保存到设备上。但是,我想利用icloud文档并将其保存到icloud并公开分享。如何使用swift来做到这一点?

我找到了保存常规文件Save iOS 8 Documents to iCloud Drive的链接。我猜测的方法是首先将它本地保存到设备上,然后将其保存到云端硬盘。但有没有人有这样的工作样本?例如,下面的UIDocument函数的可能实现是什么?

override func contents(forType typeName: String) throws -> Any {

}

override func load(fromContents contents: Any, ofType typeName: String?) throws {

}

2 个答案:

答案 0 :(得分:0)

不幸的是,几乎不可能与iCloud Drive“分享”。使用Dropbox。下面是保存文件的代码,首先需要设置DropboxClientsManager.authorizedClient变量,检查它们的dev页面。 Corepath是您文件的路径。

let client = DropboxClientsManager.authorizedClient!
client.files.upload(path: corePath, mode: .overwrite, autorename: false, input: textData).response { response, error in

    if let metadata = response {
            // Get file (or folder) metadata
        }
        if let error = error {
            switch error {
            case .routeError(let boxed, let requestId):
                switch boxed.unboxed {
                case .path(let failedPath):
                        //rint("Failed update 2 path: \(failedPath)")

                        NotificationCenter.default.post(name: Notification.Name("dbFileCreationError"), object: nil, userInfo: nil)
                        break

                    default:
                        ////rint("Unknown \(error)")
                        break
                    }
            case .internalServerError(let code, let message, let requestId):
                ////rint("InternalServerError[\(requestId)]: \(code): \(message)")
                NotificationCenter.default.post(name: Notification.Name("dbInternalServerError"), object: nil, userInfo: nil)
                break
            case .badInputError(let message, let requestId):
                ////rint("BadInputError[\(requestId)]: \(message)")
                NotificationCenter.default.post(name: Notification.Name("dbBadInputError"), object: nil, userInfo: nil)
                break
            case .authError(let authError, let requestId):
                ////rint("AuthError[\(requestId)]: \(authError)")
                NotificationCenter.default.post(name: Notification.Name("dbAuthError"), object: nil, userInfo: nil)
                break
            case .rateLimitError(let rateLimitError, let requestId):
                ////rint("RateLimitError[\(requestId)]: \(rateLimitError)")
                NotificationCenter.default.post(name: Notification.Name("dbRateLimitError"), object: nil, userInfo: nil)
                break
            case .httpError(let code, let message, let requestId):
                ////rint("HTTPError[\(requestId)]: \(code): \(message)")
                NotificationCenter.default.post(name: Notification.Name("dbHTTPError"), object: nil, userInfo: nil)
                break
            default:
                break
                }
        }
    }
}

答案 1 :(得分:0)

您也可以分享内容,但不是您通过活动应用程序思考的方式。这样做的基本代码你可以在这里看到。

@IBAction func shareButtonClicked(sender: UIButton) {
let textToShare = "Swift is awesome!  Check out this website about it!"

if let myWebsite = NSURL(string: "http://www.codingexplorer.com/") {
    let objectsToShare = [textToShare, myWebsite]
    let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)

    activityVC.popoverPresentationController?.sourceView = sender
    self.presentViewController(activityVC, animated: true, completion: nil)
}
}

本网页将对此进行更详细的说明。

http://www.codingexplorer.com/sharing-swift-app-uiactivityviewcontroller/