应用注册了监听了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
请前辈指教。
应用注册了监听了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()
。