@@ -136,6 +136,7 @@ - (NSDictionary *)dictionary
136136 return nil ;
137137}
138138
139+ #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
139140- (UIImage *)image
140141{
141142 if (content == nil && writtenURL != nil ) {
@@ -151,6 +152,22 @@ - (UIImage *)image
151152 }
152153 return nil ;
153154}
155+ #else
156+ - (NSImage *)image {
157+ if (content == nil && writtenURL != nil ) {
158+ content = [[NSImage alloc ] initWithContentsOfFile: writtenURL.path];
159+ cacheFile = YES ;
160+ return (NSImage *)content;
161+ }
162+ if ([content isKindOfClass: [NSData class ]]) {
163+ content = [[NSImage alloc ] initWithData: (NSData *)content];
164+ }
165+ if ([content isKindOfClass: [NSImage class ]]) {
166+ return (NSImage *)content;
167+ }
168+ return nil ;
169+ }
170+ #endif
154171
155172- (void )updateContent : (id <NSObject >)content_
156173{
@@ -372,6 +389,7 @@ - (NSString *)setFileWrapper:(LSFileWrapper *)fileWrapper filename:(NSString *)f
372389 return filename_;
373390}
374391
392+ #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
375393- (BOOL )writeAsset : (ALAsset *)asset_ toURL : (NSURL *)url fileManager : (NSFileManager *)fileManager error : (NSError *__autoreleasing *)outError
376394{
377395 [fileManager createFileAtPath: [url path ] contents: nil attributes: nil ];
@@ -382,7 +400,7 @@ - (BOOL)writeAsset:(ALAsset *)asset_ toURL:(NSURL *)url fileManager:(NSFileManag
382400 return NO ;
383401 }
384402 ALAssetRepresentation *rep = [asset_ defaultRepresentation ];
385- NSUInteger bytesSize = [rep size ];
403+ NSUInteger bytesSize = ( NSUInteger ) [rep size ];
386404 NSUInteger bytesRead = 0 ;
387405 NSUInteger bytesOffset = 0 ;
388406 uint8_t *buffer = calloc (BufferSize, sizeof (*buffer));
@@ -422,6 +440,27 @@ - (BOOL)writeImage:(UIImage *)image_ toURL:(NSURL *)url error:(NSError *__autore
422440 return [imageData writeToURL: url options: NSDataWritingAtomic error: outError];
423441}
424442
443+ #else
444+ - (BOOL )writeImage : (NSImage *)image_ toURL : (NSURL *)url error : (NSError *__autoreleasing *)outError
445+ {
446+ NSData *imageData;
447+ NSString *extension = [url pathExtension ];
448+
449+ [image_ lockFocus ];
450+ NSBitmapImageRep *bitmapRep = [[NSBitmapImageRep alloc ] initWithFocusedViewRect: NSMakeRect (0 , 0 , image_.size.width, image_.size.height)];
451+ [image_ unlockFocus ];
452+
453+ if ([extension isEqualToString: @" png" ]) {
454+ imageData = [bitmapRep representationUsingType: NSPNGFileType properties: nil ];
455+ }
456+ else if ([extension isEqualToString: @" jpg" ] || [extension isEqualToString: @" jpeg" ]) {
457+ imageData = [bitmapRep representationUsingType: NSJPEGFileType properties: nil ];
458+ }
459+
460+ return [imageData writeToURL: url options: NSDataWritingAtomic error: outError];
461+ }
462+ #endif
463+
425464- (BOOL )getParentUpdates : (NSMutableArray *)updates withURL : (NSURL *)url
426465{
427466 if (!parent) {
@@ -490,12 +529,18 @@ - (BOOL)writeUpdates:(NSArray *)updates filemanager:(NSFileManager *)fileManager
490529 else if ([fileContent isKindOfClass: [NSString class ]]) {
491530 success = [(NSString *)fileContent writeToURL: fileURL atomically: YES encoding: NSUTF8StringEncoding error: outError];
492531 }
532+ #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
493533 else if ([fileContent isKindOfClass: [UIImage class ]]) {
494534 success = [self writeImage: (UIImage *)fileContent toURL: fileURL error: outError];
495535 }
496536 else if ([fileContent isKindOfClass: [ALAsset class ]]) {
497537 success = [self writeAsset: (ALAsset *)fileContent toURL: fileURL fileManager: fileManager error: outError];
498538 }
539+ #else
540+ else if ([fileContent isKindOfClass: [NSImage class ]]) {
541+ success = [self writeImage: (NSImage *)fileContent toURL: fileURL error: outError];
542+ }
543+ #endif
499544 else {
500545 NSData *data = [NSPropertyListSerialization dataWithPropertyList: fileContent
501546 format: NSPropertyListBinaryFormat_v1_0
0 commit comments