應用注冊了監聽了IOS中Open In的pdf文件。我能獲取文件的地址,但是不知道怎麼獲取文件名和mime type。
- (void)handleDocumentOpenURL:(NSURL *)url
{
NSData *fileContent = [NSData dataWithContentsOfURL:url];
//would like to get the name
//would like to get the mimetype
請前輩指教。
這樣:
// Getting the filename:
NSString *fname = [url.path lastPathComponent];
// Getting MIME-type
CFStringRef ext = (CFStringRef)[url.path pathExtension];
CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, ext, NULL);
CFRelease(pathExtension);
CFStringRef mime = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType);
CFRelease(uti);
完成後還要對MIME-type進行CFRelease()
。