2015-11-03 84 views
0

我试过这段代码,但它适用于下载文件夹(示例路径:/Users/%@/Downloads/),不适用于应用程序文件夹。所以我想访问Application/iTunes/contents/,但我无法访问此路径。如何访问可可中的应用程序包内容文件夹?

我的代码:

- (IBAction)showTrashPressed:(id)sender 
{ 
    NSString *trashPath = [NSString stringWithFormat:@"/Users/%@/Applications/",NSUserName()]; 
    ////NSLog(@"%@",trashPath); 

    //[[NSWorkspace sharedWorkspace] selectFile:trashPath inFileViewerRootedAtPath:@"Finder"]; 

    [[NSWorkspace sharedWorkspace]openFile:trashPath withApplication:@"Finder"]; 
} 

回答

2

通常iTunes.app驻留在本地域中,而不是用户域的文件夹Applications

因此,您可以将路径指定为文字字符串

NSString *iTunesContentsPath = @"/Applications/iTunes.app/Contents"; 
[[NSWorkspace sharedWorkspace] openFile:iTunesContentsPath withApplication:@"Finder"]; 

但它更可靠的要求NSWorkspace的路径

NSWorkspace *sharedWorkspace = [NSWorkspace sharedWorkspace]; 
NSString *iTunesPath = [sharedWorkspace fullPathForApplication:@"iTunes"]; 
[sharedWorkspace openFile:[iTunesPath stringByAppendingPathComponent:@"Contents"] withApplication:@"Finder"]; 
+0

谢谢,此代码的工作以及.. –

相关问题