如何在iOS上的“open in”中获取我收到的文件的名称

时间:2022-06-07 17:15:08

I have registered my application to listen for pdfs in "Open In" on iOS, and I get the URL of the file but I dont know how to get the name and mime type.

我在iOS上的“Open In”中注册了我的应用程序来监听pdf,我得到了该文件的URL,但我不知道如何获取名称和mime类型。

- (void)handleDocumentOpenURL:(NSURL *)url
{
    NSData *fileContent = [NSData dataWithContentsOfURL:url];
    //would like to get the name

    //would like to get the mimetype

A link to documentation or an example would be greatly appreciated. Was not able to find anything about this online (maybe not possible).

将非常感谢文档或示例的链接。无法在网上找到任何关于此的信息(也许不可能)。

1 个解决方案

#1


1  

Like this:

喜欢这个:

// 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);

Don't forget to CFRelease() the MIME-type (mime variable) when you're done with it.

当你完成它时,不要忘记CF -lease()MIME类型(mime变量)。

#1


1  

Like this:

喜欢这个:

// 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);

Don't forget to CFRelease() the MIME-type (mime variable) when you're done with it.

当你完成它时,不要忘记CF -lease()MIME类型(mime变量)。