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

时间:2013-06-09 21:41:19

标签: 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>

感谢您提供任何帮助和建议。

1 个答案:

答案 0 :(得分:2)

我想出了该怎么做。我不得不改变:

<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>