How to create desktop icon using Xcode
I want to create a desktop icon for my application so that when user installs the application, an application icon should be created on the desktop and allow the user to run the application from the desktop icon.
I know it is not a good practice and the user can create an icon on desktop or on the dock by dragging and dropping the application to开发者_C百科 the required place, but still I want to know how to achieve this.
I'm using Xcode Version 3.2.5.
Option 1
Create the alias yourself like this:
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDesktopDirectory, NSUserDomainMask, YES);
NSString *deskPath = [paths objectAtIndex:0];
NSURL *appURL = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] bundlePath]];
NSURL *aliasURL = [[NSURL alloc] initFileURLWithPath:[deskPath stringByAppendingPathComponent:@"AppName"]];
NSError *err = nil;
NSData *bookmarkData = [appURL bookmarkDataWithOptions: NSURLBookmarkCreationSuitableForBookmarkFile includingResourceValuesForKeys:nil relativeToURL:nil error:&err];
if(bookmarkData == nil) {
// Error
} else {
if(![NSURL writeBookmarkData:bookmarkData toURL:aliasURL options:NSURLBookmarkCreationSuitableForBookmarkFile error:&err]) {
// Error
}
}
Option 2
Use NDAlias to create the alias:
http://homepage.mac.com/nathan_day/pages/source.xml
Option 3
PackageMaker features default post-installations-actions, including alias creation.
Note
It's frowned upon to create application aliases on the desktop.
Better add the application to the Dock during installation.
精彩评论