我处于某种情况,我从邮件中列出附件.每个附件都有一个与它相关联的NSURL,它表示附件数据的路径.在非图像附件的情况下,我想将预先生成的图标缩略图加载到预览的位置(即excel文档,PDF,单词等).
我目前在我的项目中有这些图像,在XCAssets捆绑包中.我可以使用[UIImage imageNamed:@“someName”]来获取它们.我似乎无法通过NSBundle的各种资源查找方法得到他们. XCAssets包是否以某种方式更改我正在寻找的图标图像的文件名?
这是我正在使用的代码.每次路径都是零.在这种情况下,我不需要使用XCAssets吗?
+ (NSURL *)mediaURLWithMessage:(SRMediaMessage*)message { NSURL *url = message.mediaURL; // if this is an image URL or non-existant,there is no work left to do,return it. if (!url || (message.secureFile.secureFileMimeType & SRSecureFileMimeTypeImage)) return url; NSString *filename = @"unknown"; switch (message.secureFile.secureFileMimeType) { case SRSecureFileMimeTypeDOC: filename = @"doc"; break; case SRSecureFileMimeTypePPT: filename = @"ppt"; break; case SRSecureFileMimeTypePDF: filename = @"pdf"; break; case SRSecureFileMimeTypeXLS: filename = @"exl"; break; case SRSecureFileMimeTypeCSV: filename = @"csv"; break; case SRSecureFileMimeTypeTXT: filename = @"txt"; break; case SRSecureFileMimeTypeRTX: filename = @"rtf"; break; default: case SRSecureFileMimeTypeMP4: // unknown icon for now. break; // unused but available: // @"ilife" } NSString *path = [[NSBundle mainBundle] pathForResource:filename ofType:nil]; if (path) url = [NSURL fileURLWithPath:path]; return url; }