【问题标题】:Filtering by .docx in ios document picker在 ios 文档选择器中按 .docx 过滤
【发布时间】:2016-04-11 01:00:34
【问题描述】:

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

System-Declared Uniform Type Identifiers 中的文档没有列出允许按 .docx 进行过滤的公共 UTType。标准 *.doc 文件存在标识符,但 *.docx 不存在,是否存在替代 UTType?

这是我当前的代码:

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#,但可以接受 Objective-c 和 swift 解决方案。

【问题讨论】:

    标签: c# ios objective-c xamarin


    【解决方案1】:

    试试org.openxmlformats.wordprocessingml.document

    【讨论】:

    • 就是杰森!
    • Apple 努力将 docx 和 Microsoft 排除在他们的系统之外:D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-19
    • 2018-05-05
    • 1970-01-01
    相关资源
    最近更新 更多