Tuesday, April 30, 2013

NSURL bookmarkDataWithContentsOfURL example ios


bookmarkDataWithContentsOfURL :error:

Initializes and returns bookmark data derived from an alias file pointed to by a specified URL.
+ (NSData *)bookmarkDataWithContentsOfURL:(NSURL *)bookmarkFileURL error:(NSError **)error
Parameters
bookmarkFileURL
The URL that points to the alias file.
error
The error that occurred in the case that the bookmark data cannot be derived.
Return Value of [NSURL bookmarkDataWithContentsOfURL]
The bookmark data for the alias file.
Discussion of [NSURL bookmarkDataWithContentsOfURL]
If bookmarkFileURL points to an alias file created prior to OS X v10.6 that contains Alias Manager information but no bookmark data, this method synthesizes bookmark data for the file.
This method returns nil if bookmark data cannot be created.
Example of [NSURL bookmarkDataWithContentsOfURL]
NSURL *aliasURL = [NSURL fileURLWithPath:@"..."];
NSData *alias = [NSURL bookmarkDataWithContentsOfURL:aliasURL error:&error];
if (alias == NULL) {
  NSLog(@"Failed aliasURL: %@", error);
}

BOOL isStale;
NSURL *realURL = [NSURL URLByResolvingBookmarkData:alias options:0 relativeToURL:nil bookmarkDataIsStale:&isStale error:&error];
if (isStale || realURL == NULL) {
  NSLog(@"Failed realURL: %@", error);
}

NSLog(@"realPath:%@", [realURL path]);