我正在使用 UIActivityViewController 以纯文本格式以及可以在其他设备上打开的自定义文件类型共享我的应用程序的内容。该文件附加到创建没有问题的电子邮件,但是它得到了与之关联的错误文件类型。创建的自定义文件是一个 NSDictionary,它使用writeToURL
.
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>
感谢您的任何帮助和建议。