iphone - UIActivityViewController 附加文​​件 - 错误的文件类型

标签 iphone ios objective-c uiactivityviewcontroller

我正在使用 UIActivityViewController 以纯文本格式和可以在其他设备上打开的自定义文件类型共享我的应用程序的内容。该文件附加到创建的电子邮件没有问题,但是它得到了与之关联的错误文件类型。创建的自定义文件是一个使用 writeToURL 的 NSDictionary。

NSMutableDictionary *theBinder = [NSMutableDictionary dictionaryWithObjects:@[@"test object"] forKeys:@[@"test key"]];
NSURL *binderURL = [NSURL fileURLWithPath:[[self cachesDirectory] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mtgbinder", [[NSUserDefaults standardUserDefaults] valueForKey:@"Current Binder"]]]];
[theBinder writeToURL:binderURL atomically:YES];

NSArray *activityItems = [NSArray arrayWithObjects:binderContents, binderURL, nil];

UIActivityViewController *shareView = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
shareView.excludedActivityTypes = @[UIActivityTypePostToTwitter, UIActivityTypePostToWeibo];
[self presentViewController:shareView animated:YES completion:nil];

文件按预期正确创建:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>test key</key>
    <string>test object</string>
</dict>
</plist>

但是,当我随后尝试从另一个应用程序打开该文件时,扩展名更改为 csv。我的应用程序能够打开和导出我的 mtgbinder 文件类型和 CSV。我是不是对 UTExportedTypeDeclarations 做错了什么?

<key>UTExportedTypeDeclarations</key>
    <array>
        <dict>
            <key>UTTypeConformsTo</key>
            <array>
                <string>public.data</string>
            </array>
            <key>UTTypeIdentifier</key>
            <string>com.chichapps.MTG-Binder.csv</string>
            <key>UTTypeTagSpecification</key>
            <dict>
                <key>public.filename-extension</key>
                <string>csv</string>
                <key>public.mime-type</key>
                <string>application/MTG-Binder</string>
            </dict>
        </dict>
        <dict>
            <key>UTTypeIdentifier</key>
            <string>com.chichapps.MTG-Binder.mtgbinder</string>
            <key>UTTypeDescription</key>
            <string>MTG Binder Document</string>
            <key>UTTypeTagSpecification</key>
            <dict>
                <key>public.mime-type</key>
                <string>application/MTG-Binder</string>
                <key>public.filename-extension</key>
                <string>mtgbinder</string>
            </dict>
            <key>UTTypeConformsTo</key>
            <array>
                <string>public.data</string>
            </array>
        </dict>
    </array>
    <key>CFBundleDocumentTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeName</key>
            <string>MTG Binder Document</string>
            <key>LSHandlerRank</key>
            <string>Owner</string>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>LSItemContentTypes</key>
            <array>
                <string>com.chichapps.MTG-Binder.csv</string>
                <string>com.chichapps.MTG-Binder.mtgbinder</string>
            </array>
        </dict>
    </array>

感谢您的帮助和建议。

最佳答案

我想好了要做什么。我不得不改变:

<dict>
    <key>UTTypeConformsTo</key>
    <array>
        <string>public.data</string>
    </array>
    <key>UTTypeIdentifier</key>
    <string>com.chichapps.MTG-Binder.csv</string>
    <key>UTTypeTagSpecification</key>
    <dict>
        <key>public.filename-extension</key>
        <string>csv</string>
        <key>public.mime-type</key>
        <string>application/MTG-Binder</string>
    </dict>
</dict>

收件人:

<dict>
    <key>UTTypeConformsTo</key>
    <array>
        <string>public.data</string>
    </array>
    <key>UTTypeIdentifier</key>
    <string>com.chichapps.MTG-Binder.csv</string>
    <key>UTTypeTagSpecification</key>
    <dict>
        <key>public.filename-extension</key>
        <string>csv</string>
        <key>public.mime-type</key>
        <string>application/csv</string> //Changing this fixed the problem
    </dict>
</dict>

关于iphone - UIActivityViewController 附加文​​件 - 错误的文件类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17014457/

相关文章:

iphone - 适用于 iPhone 的 Appdelegate,但不适用于 iPad 版本

iphone - 在 UITextView 中向上/向下移动光标

ios - 在 Swift 框架中添加 Objective C 框架

ios - 如何在 ios 的歌曲加载时间中显示或隐藏事件指示器

ios - 在 iOS 中取消付款?

iphone - 如何跟踪 AVAssetWriter 的写入进度?

ios - fatal error : Index out of range

ios - 在 Swift 中打印当前文件的类名

iphone - View 不是从iOS7状态栏的底部开始

ios - UIBarButtonItem 点击区域