Created
January 9, 2015 00:43
-
-
Save tjw/7dda6610979e084f727c to your computer and use it in GitHub Desktop.
NSURLThumbnailDictionaryKey test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Cocoa/Cocoa.h> | |
/* | |
clang -fobjc-arc -Wall preview-from-url.m -o /tmp/preview-from-url -framework Cocoa | |
When run on a file in my iCloud Drive: | |
2015-01-08 16:39:54.008 preview-from-url[23221:261259] NSURLThumbnailDictionaryKey = { | |
NSThumbnail1024x1024SizeKey = "<NSImage 0x7fd6b34228f0 Size={790, 1024} Reps=(\n \"<NSCGImageSnapshotRep:0x7fd6b34249e0 cgImage=<CGImage 0x7fd6b3423de0>>\"\n)>"; | |
} | |
Copy that same file out to my Desktop: | |
2015-01-08 16:40:19.021 preview-from-url[23235:261769] NSURLThumbnailDictionaryKey = (null) | |
*/ | |
int main(int argc, char *argv[]) | |
{ | |
if (argc != 2) { | |
fprintf(stderr, "usage: %s path", argv[0]); | |
return 1; | |
} | |
NSString *path = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:argv[1] length:strlen(argv[1])]; | |
NSURL *fileURL = [NSURL fileURLWithPath:path]; | |
NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil]; | |
__autoreleasing NSError *error; | |
__block BOOL success = NO; | |
[coordinator coordinateReadingItemAtURL:fileURL options:0 error:&error byAccessor:^(NSURL *newURL){ | |
__autoreleasing id value; | |
__autoreleasing NSError *resourceError; | |
if (![newURL getResourceValue:&value forKey:NSURLThumbnailDictionaryKey error:&resourceError]) { | |
NSLog(@"Error getting resource value: %@", resourceError); | |
return; | |
} | |
NSLog(@"NSURLThumbnailDictionaryKey = %@", value); | |
success = YES; | |
}]; | |
if (!success) { | |
NSLog(@"Failed to read file: %@", error); | |
return 1; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment