簡體   English   中英

UIActivityViewController附加文件-錯誤的文件類型

[英]UIActivityViewController Attaching File - Wrong File Type

我正在使用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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM