LSGetApplicationForItem -or- my crazy adventure with launch services
LSGetApplicationForItem -or- my crazy adventure with launch services
- Subject: LSGetApplicationForItem -or- my crazy adventure with launch services
- From: email@hidden
- Date: Wed, 5 Sep 2001 23:11:04 -0700
I am using launch services quit a but in my app, but I am having some
troubles. I don't really get a lot of it, so this is me walking blindly
through header files.
I am trying to get the application that a file will open in, but I crash
because of SIGSEGV (segmentation i think)
here's the relevant code:
- (void)getFileInfo:(NSString *)fullPath
{
FSRef ref;
FSPathMakeRef([fullPath cString], &ref, NULL);
if (![manager fileExistsAtPath:fullPath isDirectory:&isDir] || !isDir)
{
[opensWithField setStringValue:(NSString
*)LSGetApplicationForItem(&ref, kLSRolesAll, NULL, NULL)];
}
}
there is other stuff in there. The full function is:
- (void)getFileInfo:(NSString *)fullPath
{
NSFileManager *manager = [NSFileManager defaultManager];
NSDictionary *fattrs = [manager fileAttributesAtPath:fullPath
traverseLink:YES];
FSRef ref;
BOOL isDir;
FSPathMakeRef([fullPath cString], &ref, NULL);
[dirField setStringValue:fullPath];
if (![manager fileExistsAtPath:fullPath isDirectory:&isDir] ||
!isDir)
{
[typeField
setStringValue:RemoveQuotesFromString(NSHFSTypeOfFile(fullPath))];
[creatorField
setStringValue:RemoveQuotesFromString(HFSCreatorOfFile(fullPath))];
[sizeField setStringValue:[[fattrs objectForKey:NSFileSize]
stringValue]];
[ownerField setStringValue:[fattrs
objectForKey:NSFileOwnerAccountName]];
[groupField setStringValue:[fattrs
objectForKey:NSFileGroupOwnerAccountName]];
[opensWithField setStringValue:(NSString
*)LSGetApplicationForItem(&ref, kLSRolesAll, NULL, NULL)];
}
else
{
[typeField setStringValue:@""];
[creatorField setStringValue:@""];
[sizeField setStringValue:@""];
[ownerField setStringValue:@""];
[groupField setStringValue:@""];
[opensWithField setStringValue:@""];
}
}
thanks,
sam