小编Joh*_*n K的帖子

在iOS中使用mime类型或UTI类型的内置图标

问题:

我希望能够在我的二进制文件内容列表中使用标准mime类型(或UTI类型)的内置iOS图标.

背景:

我已经研究过使用新的(自3.2)文档体系结构,但是使用UIDocumentInteractionController似乎假设实际的二进制文件已经在本地设备上了.

在我的情况下,我有一个远程服务器的文件列表,并知道远程文件的mime类型,名称,标题等,所以我只想显示带有图标的文件列表(实际二进制文件仅根据需要加载).

我从服务器获取的元数据包含二进制文件的正确mime类型,所以理论上我只想根据类型获取系统图标.

解决?

我尝试了以下"黑客"作为概念的证明,它似乎工作,但这似乎不是最好的方式...

//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 …
Run Code Online (Sandbox Code Playgroud)

iphone ios uidocumentinteraction

13
推荐指数
3
解决办法
4855
查看次数

标签 统计

ios ×1

iphone ×1

uidocumentinteraction ×1