我正在学习更多关于ios扩展的知识,例如:
在所有这些中,我没有学习上的困难,但最近我尝试学习"文档提供者扩展",并且令我惊讶的是,没有在互联网上找到任何关于如何使用它的相关教程(与其他人一样一步一步) ).
我找到的唯一选择是使用文档,我了解到他可以从其他应用程序访问共享文档,您还可以在应用程序中共享自己的现有文档.
我在网上找到的唯一一个教程是MacStories网站,但他使用的是iCloud,而且这次我不想使用iCloud,我想要做文档说:
允许其他应用访问您应用管理的文档(不使用iCloud)
在我的情况下,我已经知道"提供者文档扩展"是如何工作的,因此设法创建一个新的目标类型"文档提供者扩展",并且只有这一点.有谁知道这个扩展如何工作?
我正在尝试下载文件夹层次结构中包含的文件UIDocumentPickerController.我用我从获取URL documentPicker:DidPickDocumentsAtURLs:用NSFileCoordinator.
对于iCloud Drive文件提供程序提供的文件夹,它在访问块中提供的URL显然是.zip文件 - 如果文件最初未下载 - 仅包含foo.icloud归档NSURL的文件.如何在压缩过程之前确保已下载这些文件?
我是否应该手动取消归档并将它们再次送入NSFileCoordinator?或者我需要使用startDownloadingUbiquitousItemAtURL:error:?我认为使用它UIDocumentPickerController应该让我摆脱所有的手动协调逻辑.
我错过了什么?
ios nsfilecoordinator uidocumentpickervc icloud-drive uidocumentpickerviewcontroller
我正在使用带有导入模式的UIDocumentPickerViewController(UIDocumentPickerModeImport),以便让用户从云存储提供程序(dropbox等)导入文档.每次用户重复导入过程时,他都必须从其云存储的根目录开始浏览其文件夹层次结构.
有没有办法在给定的子目录上显示文档选择器?
我知道这个方法:
[NSURL bookmarkDataWithOptions:includingResourceValuesForKeys:relativeToURL:error:]
Run Code Online (Sandbox Code Playgroud)
但我无法用文件选择器演示选项连接点.我希望选择器选项能够在给定的书签目录URL上显示文档选择器.
objective-c ios uidocumentpickervc icloud-drive uidocumentpickerviewcontroller
我使用此方法来显示UIDocumentPicker:
func showDocumentPicker(){
let docPicker = UIDocumentPickerViewController(documentTypes: ["public.composite-content "], inMode: UIDocumentPickerMode.Import)
docPicker.delegate = self
docPicker.modalPresentationStyle = UIModalPresentationStyle.FullScreen
self.presentViewController(docPicker, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
UIDocumentPicker很好地显示,但它总是显示
无文档,iCloud Drive中的文档不可用,因为禁用了iCloud Documents&Data设置

但是当我检查iCloud状态时,iCloud Drive已启用!(我的应用程序甚至出现在那里的设置中,也启用了!)

这发生在模拟器和设备上(通过Apple TestFlight分发的预发布)
我从云端导入文件时遇到问题。我正在处理一个我实际上没有创建的自定义文件类型。所以我不知道实际的扩展类型是什么(例如 com.example.pdf)。文件以 .toc 结尾,那么有没有办法我只能接受以 .toc 结尾的文件?
例如这样的事情:
UIDocumentPickerViewController(documentTypes: [String("*.toc")], in: .import)
Run Code Online (Sandbox Code Playgroud)
如果这是不可能的,有没有办法允许选择任何文件?从那里我可以只检查最后 4 位数字并让用户知道文件必须以 .toc 结尾?
为了尝试获取有关文件类型的更多信息,我还在终端中运行了以下命令:
file -I filename.toc
Run Code Online (Sandbox Code Playgroud)
返回:
filename.toc: text/html; charset=us-ascii
Run Code Online (Sandbox Code Playgroud)
因为这表示它是一个“text/html”文件,我尝试使用:
UIDocumentPickerViewController(documentTypes: [String(kUTTypeText)], in: .import)
Run Code Online (Sandbox Code Playgroud)
但是,这不允许我选择文件...有人有什么想法吗?
我在 Xcode 7.0 beta 6 中使用 Swift 2
长话短说,我正在尝试解决如何设置 .navigationBar.barStyle以及navigationBar.tintColor何时使用文档选择器访问 iCloud——即UIDocumentPickerViewController.
我试过例如:
/...
documentPicker.navigationController!.navigationBar.barStyle = UIBarStyle.Default
documentPicker.navigationController!.navigationBar.tintColor = UIColor.orangeColor()
/...
Run Code Online (Sandbox Code Playgroud)
例如。在这里,我在导航控制器中嵌入了一个视图控制器:
在MyNavigationController我可以设置.barStyle和.tintStyle如下:
class MyNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationBar.barStyle = UIBarStyle.Default
self.navigationBar.tintColor = UIColor.orangeColor()
}
}
Run Code Online (Sandbox Code Playgroud)
因此,.tintStyle为橙色如下:
iCloud 已启用并FirstViewController符合UIDocumentPickerDelegate. 条形按钮调用IBAction如下代码所示的函数FirstViewController:
class FirstViewController: UIViewController, UIDocumentPickerDelegate {
// ...
@IBAction func importDocument(sender: UIBarButtonItem) {
let documentPicker: UIDocumentPickerViewController …Run Code Online (Sandbox Code Playgroud) 我有一个文档选择器,但选择文档后,didPickDocumentAt 部分永远不会被触发。在我更新 swift 之前它可以工作,现在有什么不同吗?
func selectDocument(_ sender: UIButton!){
let documentPickerVC = UIDocumentPickerViewController(documentTypes: ["org.openxmlformats.wordprocessingml.document", "com.microsoft.word.doc"], in: UIDocumentPickerMode.import)
documentPickerVC.delegate = self
self.present(documentPickerVC, animated: true, completion: nil)
}
func documentPicker(_ documentPicker: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
print("file picked: \(url)")
documentPicker.dismiss(animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
也没有什么“失败”,它只是没有调用该documentPicker方法。
我有一个类似的用于选择媒体的工具,并且效果很好......
func selectMedia(_ sender: UIButton!){
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary){
picker.delegate = self
picker.allowsEditing = false
picker.mediaTypes = [kUTTypeMovie as String]
self.present(picker, animated: true, completion: nil)
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info:[String: Any]) {
let url = …Run Code Online (Sandbox Code Playgroud) 如何在选择它并使用 UIDocumentPickerViewController 下载到设备之前在 iCloud 中找到文档的大小。我可以将文档下载到设备然后转换为 NSData,我可以确定文件大小,但是我们可以避免下载文档本身吗?在下载之前预先确定文件大小。我在 uidocumentpickerviewcontroller 中找不到任何方法或属性。
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
NSError *error = nil;
[coordinator coordinateReadingItemAtURL:url options:0 error:&error byAccessor:^(NSURL *newURL) {
//assuming the file coordinator has downloaded the file here and provided the new url here
}
}
Run Code Online (Sandbox Code Playgroud) 当我尝试从 iCloud Drive 或 Dropbox 将文件导入到我的服务器时, startAccessingSecurityScopedResource()仅返回 false 设备,但在模拟器(Xcode 8、Swift 2.3、最低目标 8.0)中测试时返回 true。
这是我的代码:
{
func showCloudDriveAction(inputBar: NAChatInputBar) {
let documentmenuPicker = UIDocumentMenuViewController(documentTypes: ["public.data"], inMode: .Import)
documentmenuPicker.delegate = self
presentViewController?.presentViewController(documentmenuPicker, animated: true, completion: nil)
}
}
extension NAChatInputBarPresenter: UIDocumentPickerDelegate, UIDocumentMenuDelegate {
public func documentMenu(documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {
documentPicker.delegate = self
self.presentViewController?.presentViewController(documentPicker, animated: true, completion: nil)
}
public func documentPicker(controller: UIDocumentPickerViewController, didPickDocumentAtURL url: NSURL) {
if url.startAccessingSecurityScopedResource() {
guard let path = url.path, data = NSData(contentsOfFile: path) else …Run Code Online (Sandbox Code Playgroud) 我有一个关于没有为 DocumentPickerViewController 调用委托方法的查询,这是背景,我只需要从我的文件应用程序中导入可用的资源,因此我使用 UIDocumentPickerViewController。
我有一个单独的 ViewController,我将 documentPickerViewController 的视图添加为子视图并添加它的委托。我的 ViewController 的代码是这样的。
var documentPickerController: UIDocumentPickerViewController!
let supportedUTI = [kUTTypeImage,kUTTypeSpreadsheet,kUTTypePresentation,kUTTypeDatabase,kUTTypeFolder,kUTTypeZipArchive,kUTTypeVideo, kUTTypeAudiovisualContent]
documentPickerController = UIDocumentPickerViewController.init(documentTypes: supportedUTI as [String], in: .import)
documentPickerController.delegate = self
documentPickerController.allowsMultipleSelection = false
view.addSubview(documentPickerController.view)
Run Code Online (Sandbox Code Playgroud)
现在,当我看到 pickercontroller 已打开,当我点击 Cancel 时会documentPickerWasCancelled被调用,但是当我选择一个文件时documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]不会被调用。
我试图进一步深入了解我所看到的内容,而不是显示我的 ViewController,如果我像这样直接显示 pickerViewController,我会将选择器的视图添加为子视图
UIDocumentPickerViewController *dc = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:[self UTITypes] inMode:UIDocumentPickerModeImport];
dc.delegate = self;
[MainVC presentViewController:dc animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
两个委托方法都被调用得很好。我不明白为什么。有人可以在这里帮助我吗!!提前致谢!!
ios ×9
swift ×6
icloud ×3
uidocumentpickerviewcontroller ×3
icloud-drive ×2
objective-c ×2
import ×1
ios8 ×1
uidocument ×1