我为此苦苦挣扎,我想获得所有可以打开确定的路径/文件扩展名的捆绑包。
如果您有文件扩展名,则可以通过以下方式获取所有可以编辑它的捆绑包:
//All Bundle Ids
NSString *pathExtension = @"docx";
CFArrayRef utisRef = UTTypeCreateAllIdentifiersForTag(kUTTagClassFilenameExtension,(__bridge CFStringRef) pathExtension,nil);
NSLog( @"UTI: utisRef %@", utisRef);
NSArray *utis = CFBridgingRelease(utisRef);
NSMutableSet *mutableSet = [[NSMutableSet alloc] init];
for (NSString *uti in utis) {
CFArrayRef bundleIDsRef = LSCopyAllRoleHandlersForContentType((__bridge CFStringRef) uti,kLSRolesEditor);
[mutableSet addObjectsFromArray:CFBridgingRelease(bundleIDsRef)];
}
NSLog( @"bundleIDs: %@", mutableSet);
如果您有文件路径并且想要获取所有可以编辑它的应用程序位置,您可以使用以下命令:
//Location of apps
NSString *str = @"/Users/ricardoanjos/Library/Developer/Xcode/DerivedData/EgnyteDrive-hforbniifiojczefbnwanzxakvlr/Build/Products/Debug/1.pdf";
NSURL* url = [[NSURL alloc] initFileURLWithPath:str];
CFURLRef urlRef = (__bridge CFURLRef)url;
CFArrayRef appUrlsRef = LSCopyApplicationURLsForURL(urlRef, kLSRolesEditor);
NSArray *appUrls = CFBridgingRelease(appUrlsRef);
NSLog(@"appUrls: %@", appUrls);
我希望它会有所帮助。