首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ios文档选择器中的.docx过滤

ios文档选择器中的.docx过滤
EN

Stack Overflow用户
提问于 2016-04-11 01:00:34
回答 2查看 1.9K关注 0票数 8

要向UIDocumentMenuViewController提供什么统一类型标识符以允许用户选择*.docx文件?

系统声明的统一类型标识符中的文档没有列出允许通过.docx进行过滤的公共UTType。对于标准*.doc文件存在标识符,但不存在*.docx,是否存在替代UTType?

这是我目前的代码:

代码语言:javascript
复制
var allowedDocumentTypes = new string[] {
    UTType.RTF,
    UTType.Text,
    UTType.PDF,
    UTType.UTF8PlainText,
    UTType.RTFD,
    UTType.UTF16ExternalPlainText,
    UTType.UTF16PlainText,
    UTType.UTF8PlainText,
    UTType.FlatRTFD,
    "com.microsoft.word.doc",
    "com.microsoft.word.docx" // An attempt to include docx filtering.
};

var pickerMenu = new UIDocumentMenuViewController(allowedDocumentTypes, UIDocumentPickerMode.Open);
pickerMenu.DidPickDocumentPicker += (sender, args) =>
{
    args.DocumentPicker.DidPickDocument += (sndr, pArgs) =>
    {
        var securityEnabled = pArgs.Url.StartAccessingSecurityScopedResource();

        FileInfo fi = new FileInfo(pArgs.Url.Path);

        var result = new SelectFileResult();
        result.FilePath = fi.FullName;
        result.FileName = fi.Name;

        NSUrlRequest urlReq = NSUrlRequest.FromUrl(pArgs.Url);
        NSUrlResponse response;
        NSError error;;
        var data = NSUrlConnection.SendSynchronousRequest(urlReq, out response, out error);

        result.MimeType = response.MimeType;

        Action onFileConsumeDone = () =>
        {
            pArgs.Url.StopAccessingSecurityScopedResource();
        };

        onFileSelected(result, onFileConsumeDone);

    };

    // Display the document picker
    AppDelegate.TopViewController.PresentViewController(args.DocumentPicker, true, null);
};

pickerMenu.ModalPresentationStyle = UIModalPresentationStyle.Popover;
AppDelegate.TopViewController.PresentViewController(pickerMenu, true, null);

我在黑暗中进行了一次尝试,并包含了标识符com.microsoft.word.docx,但它不会触发docx的过滤。

我目前的解决方案是C#,但目标-c和快速解决方案被接受.

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-04-11 01:03:42

试试org.openxmlformats.wordprocessingml.document

票数 8
EN

Stack Overflow用户

发布于 2022-04-13 06:24:52

试着让supportedTypes: UTType = UTType.content

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36538257

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档