Playback Notifications: Prevent crash when notifying a track with unusable album artwork

CQTexperiment
Christopher Snowhill 2022-01-11 20:39:10 -08:00
parent 557e0bd399
commit 3b62842021
1 changed files with 18 additions and 15 deletions

View File

@ -208,23 +208,26 @@ typedef NS_ENUM(NSInteger, TrackStatus) { TrackPlaying, TrackPaused, TrackStoppe
CGImageRef cgRef = [image CGImageForProposedRect:NULL CGImageRef cgRef = [image CGImageForProposedRect:NULL
context:nil context:nil
hints:nil]; hints:nil];
NSBitmapImageRep *newRep =
[[NSBitmapImageRep alloc] initWithCGImage:cgRef];
NSData *jpgData = [newRep
representationUsingType:NSBitmapImageFileTypeJPEG
properties:@{NSImageCompressionFactor : @0.5f}];
[jpgData writeToURL:fileURL atomically:YES];
UNNotificationAttachment *icon = if (cgRef) {
[UNNotificationAttachment attachmentWithIdentifier:@"art" NSBitmapImageRep *newRep =
URL:fileURL [[NSBitmapImageRep alloc] initWithCGImage:cgRef];
options:nil NSData *jpgData = [newRep
error:&error]; representationUsingType:NSBitmapImageFileTypeJPEG
if (error) { properties:@{NSImageCompressionFactor : @0.5f}];
[jpgData writeToURL:fileURL atomically:YES];
UNNotificationAttachment *icon =
[UNNotificationAttachment attachmentWithIdentifier:@"art"
URL:fileURL
options:nil
error:&error];
if (error) {
// We have size limit of 10MB per image attachment. // We have size limit of 10MB per image attachment.
NSLog(@"%@", error.localizedDescription); NSLog(@"%@", error.localizedDescription);
} else { } else {
content.attachments = @[ icon ]; content.attachments = @[ icon ];
}
} }
} }
} }