我想在我的iOS应用程序中选择任何类型的文件(.pdf,.docs,.xlsx,.jpeg,.txt,.rtf等).点击上传按钮,我希望我的应用程序打开一个目录并选择文件(DocumentsPicker)
@IBAction pickDocument(sender: UIButton) {
//Open Document Picker
}
Run Code Online (Sandbox Code Playgroud)
这样做的方法是什么Swift?
通常,UIDocumentPicker的行为是您呈现的,然后用户必须使用右上角的"位置"菜单在服务之间切换.默认情况下是否可以首先显示"Dropbox"或"Google Drive"?几乎就像我们"深入链接"到UIDocumentPicker服务一样.
似乎Slack App能够做到这一点以及MyMail应用程序,但我无法找到它的API.有任何想法吗?

我已经尝试了两天多来写一个文件到iCloud驱动器.我尝试直接编写一个简单的文本文件,然后在本地移动它,使用UIDocumentMenuViewController等.我没有得到任何错误的代码和单步执行调试器,它看起来很成功,但当我检查文件是否存在或至少iCloud目录,那里什么都没有.我尝试了模拟器和我的iPhone,触发了iCloud同步,以及我能想到的其他一切.
我的主要目标是简单地将文本文件写入iCloud驱动器,后来将成为"数字"文件
我已经设置了我的plist文件和我的权利:
<key>NSUbiquitousContainers</key>
<dict>
<key>iCloud.com.paul.c.$(PRODUCT_NAME:rfc1034identifier)</key>
<dict>
<key>NSUbiquitousContainerIsDocumentScopePublic</key>
<true/>
<key>NSUbiquitousContainerName</key>
<string>myCloudTest</string>
<key>NSUbiquitousContainerSupportedFolderLevels</key>
<string>Any</string>
</dict>
</dict>
Run Code Online (Sandbox Code Playgroud)
我还提到了捆绑版本,如下所述:将iOS 8文档保存到iCloud Drive
我已经尝试了几十个没有运气的教程.我的最新代码基于此示例:https://medium.com/ios-os-x-development/icloud-drive-documents-1a46b5706fe1
这是我的代码:
@IBAction func ExportFile(sender: AnyObject) {
var error:NSError?
let iCloudDocumentsURL = NSFileManager.defaultManager().URLForUbiquityContainerIdentifier(nil)?.URLByAppendingPathComponent("myCloudTest")
//is iCloud working?
if iCloudDocumentsURL != nil {
//Create the Directory if it doesn't exist
if (!NSFileManager.defaultManager().fileExistsAtPath(iCloudDocumentsURL!.path!, isDirectory: nil)) {
//This gets skipped after initial run saying directory exists, but still don't see it on iCloud
NSFileManager.defaultManager().createDirectoryAtURL(iCloudDocumentsURL!, withIntermediateDirectories: true, attributes: nil, error: nil)
}
} …Run Code Online (Sandbox Code Playgroud) 我有文件下载选项。当用户从我的应用程序下载文档时,我需要将其存储到已经安装在用户移动设备中的用户iCloud Drive中。我已经在Web和Xcode中都配置了iCloud,但是问题是我无法正确将文件复制到iCloud Drive。文件已成功下载,并且也已移至iCloud,但文件不会出现在iCloud Drive App中。这是我尝试的代码:
<key>NSUbiquitousContainers</key>
<dict>
<key>iCloud.MyAppBundleIdentifier</key>
<dict>
<key>NSUbiquitousContainerIsDocumentScopePublic</key>
<true/>
<key>NSUbiquitousContainerName</key>
<string>iCloudDriveDemo</string>
<key>NSUbiquitousContainerSupportedFolderLevels</key>
<string>Any</string>
</dict>
</dict>
Run Code Online (Sandbox Code Playgroud)
这是我的iCloud存储代码:
func DownloadDocumnt()
{
print("Selected URL: \(self.SelectedDownloadURL)")
let fileURL = URL(string: "\(self.SelectedDownloadURL)")!
let documentsUrl:URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first as URL!
let destinationFileUrl = documentsUrl.appendingPathComponent("Libra-\(self.SelectedDownloadFileName)")
let sessionConfig = URLSessionConfiguration.default
let session = URLSession(configuration: sessionConfig)
let request = URLRequest(url:fileURL)
let task = session.downloadTask(with: request) { (tempLocalUrl, response, error) in
if let tempLocalUrl = tempLocalUrl, error == nil
{
if let statusCode = (response as? …Run Code Online (Sandbox Code Playgroud) icloud ×4
ios ×4
swift ×3
uidocument ×2
drive ×1
dropbox ×1
icloud-drive ×1
ios8 ×1
objective-c ×1
swift3 ×1