问题:
我希望能够在我的二进制文件内容列表中使用标准 mime 类型(或 UTI 类型)的内置 iOS 图标。
背景:
我研究过使用新的(自 3.2 起)文档架构,但使用 UIDocumentInteractionController 似乎假设实际的二进制文件已经在本地设备上。
在我的例子中,我有一个来自远程服务器的文件列表,并且知道远程文件的 MIME 类型、名称、标题等,所以我只想显示一个带有图标的文件列表(实际的二进制文件只在需要时加载).
我从服务器获取的元数据包含二进制文件的正确 MIME 类型,因此理论上我只想根据类型获取系统图标。
解决办法?
我已经尝试了以下“hack”作为概念证明,它似乎有效,但这似乎不是最好的方法......
//Need to initialize this way or the doc controller doesn't work
NSURL*fooUrl = [NSURL URLWithString:@"file://foot.dat"];
UIDocumentInteractionController* docController = [[UIDocumentInteractionController interactionControllerWithURL:fooUrl] retain];
UIImage* thumbnail = nil;
//Need to convert from mime type to a UTI to be able to get icons for the document
NSString *uti = [NSMakeCollectable(UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (CFStringRef)self.contentType, NULL)) autorelease];
//Tell the doc controller what UTI type we want
docController.UTI = uti;
//The doc controller now seems to have icon(s) for the type I ask for...
NSArray* icons = docController.icons;
if([icons count] > 0) {
thumbnail = [icons objectAtIndex:0];
}
return thumbnail;
最佳答案
您可以创建一个 UIDocumentInteractionController
而无需指定 URL。该类的 header 表示图标由 name
确定(如果已设置),否则由 URL
确定。
UIDocumentInteractionController* docController = [[UIDocumentInteractionController alloc] init];
docController.name = @"foo.dat";
NSArray* icons = docController.icons;
// Do something with icons
...
[docController release];
关于iphone - 在 iOS 中使用 mime 类型或 UTI 类型的内置图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5876895/