2017-04-26 29 views
0

我已經創建了一個電影文件,並能夠將其保存到本地設備上。不過,我想利用icloud文件並將其保存爲icloud並公開分享。如何使用swift做到這一點?如何將AVCaptureMovieFileOutput保存到iCloud

我發現此保存一般文件的鏈接,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 { 

} 

回答

0

不幸的是,它幾乎不可能與iCloud Drive「共享」。使用Dropbox。這裏是保存你的文件的代碼,你需要首先設置DropboxClientsManager.authorizedClient變量,然後檢查他們的開發頁面。 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 
       } 
     } 
    } 
} 
+0

你能爲什麼這是不可能與icloud的分享的東西詳細點嗎? –

+0

David,雲驅動器沒有提供共享文檔的API,期間。如果您使用資產,您可以通過cloudKit分享內容,但您可以通過專用應用與其他appleID用戶分享內容。您還可以通過活動應用分享內容,我可以在第二個答案中發佈代碼。 – user3069232

+0

這在蘋果部分很奇怪。按照您的建議使用Dropbox可以共享視頻文件?是否收取費用,還是僅佔用用戶當前分配的磁盤空間?換句話說,無論他們目前是免費還是付費。 –

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/

相關問題