我正在尝试为我的iOS应用程序创建/导出一种独有的UTI类型(非常类似于Instagram如何独家处理UTI com.instagram.exclusivegram)。
基本上,如果其他应用程序想要能够在已注册拍照的任何应用程序中打开照片,则希望com.photoapp.photo成为可用的应用程序。然后,我希望com.photoapp.exclusive只能在我的应用程序中打开(类似于com.instagram.exclusivegram)。
但是,在我的设备上遇到的问题是,即使使用com.photoapp.exclusive,UIDocumentController也会提示我在PhotoApp或DropBox中打开它,而不仅仅是在PhotoApp中打开。
我有一个注册UTI的应用程序以及一个示例应用程序,我正在使用它来检查打开能力。我在示例应用程序中使用的代码如下:
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"photoapp://"]]) {
NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"derp.png"], 1.0);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *fullPathToFile = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"photoapp.pae"];
[imageData writeToFile:fullPathToFile atomically:NO];
interactionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:[NSString stringWithFormat:@"file://%@", fullPathToFile]]];
interactionController.UTI = @"com.photoapp.exclusive";
interactionController.delegate = self;
[interactionController presentOpenInMenuFromRect:self.view.frame inView:self.view animated:YES];
}
以下是我应用程序的plist文件中的内容:
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeDescription</key>
<string>Exclusive PhotoApp Photo</string>
<key>UTTypeConformsTo</key>
<array>
<string>com.photoapp.photo</string>
</array>
<key>UTTypeIdentifier</key>
<string>com.photoapp.exclusive</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<string>pae</string>
</dict>
</dict>
<dict>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<string>pa</string>
</dict>
<key>UTTypeIdentifier</key>
<string>com.photoapp.photo</string>
<key>UTTypeDescription</key>
<string>PhotoApp Photo</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.png</string>
<string>public.jpeg</string>
</array>
</dict>
</array>
<key>UIFileSharingEnabled</key>
<true/>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>LSItemContentTypes</key>
<array>
<string>com.photoapp.exclusive</string>
<string>com.photoapp.photo</string>
</array>
<key>CFBundleTypeName</key>
<string>Photo</string>
<key>LSHandlerRank</key>
<string>Default</string>
</dict>
</array>
public.png
或public.jpeg
或类似的标准,所有指定可以打开这些 UTI 文件的应用程序都能够打开它们。如果您删除了UTTypeConformsTo
数组,那么这个问题就会解决。 - Gregcom.photoapp.exclusive
符合com.photoapp.photo
。保持com.photoapp.photo
不变,只是不为com.photoapp.exclusive
指定任何符合性。 - Greg