Created
December 9, 2019 23:15
-
-
Save steipete/ed0fd2dfe821a591e68d075d2d80750e to your computer and use it in GitHub Desktop.
Needed to implement Open Recent on Mac Catalyst. See https://speakerdeck.com/steipete/shipping-a-mac-catalyst-app-the-good-the-bad-and-the-ugly
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
@implementation UIImage (ResourceProxyHack) | |
+ (UIImage *)_iconForResourceProxy:(id)proxy format:(int)format { | |
// HACK: proxy seems garbage so we always show PDF for now. | |
let cgImage = [_bridge imageForFileType:@"pdf"]; | |
// HACK: We use mainScreen here but could have multiple screens. | |
let image = [UIImage imageWithCGImage:cgImage scale:UIScreen.mainScreen.scale orientation:UIImageOrientationUp]; | |
return image; | |
} | |
@end | |
// In the AppKit bridge: | |
- (CGImageRef)imageForFileType:(NSString *)fileType { | |
NSImage *image = [NSWorkspace.sharedWorkspace iconForFileType:fileType]; | |
image.size = NSMakeSize(16, 16); | |
CGImageRef cgRef = [image CGImageForProposedRect:NULL context:nil hints:nil]; | |
return cgRef; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment