From 3b628420211f2eac1c5f377df81d4a834fb0d712 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Tue, 11 Jan 2022 20:39:10 -0800 Subject: [PATCH] Playback Notifications: Prevent crash when notifying a track with unusable album artwork --- Application/PlaybackEventController.m | 33 +++++++++++++++------------ 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/Application/PlaybackEventController.m b/Application/PlaybackEventController.m index 319d8ced1..f8ff08ee2 100644 --- a/Application/PlaybackEventController.m +++ b/Application/PlaybackEventController.m @@ -208,23 +208,26 @@ typedef NS_ENUM(NSInteger, TrackStatus) { TrackPlaying, TrackPaused, TrackStoppe CGImageRef cgRef = [image CGImageForProposedRect:NULL context:nil hints:nil]; - NSBitmapImageRep *newRep = - [[NSBitmapImageRep alloc] initWithCGImage:cgRef]; - NSData *jpgData = [newRep - representationUsingType:NSBitmapImageFileTypeJPEG - properties:@{NSImageCompressionFactor : @0.5f}]; - [jpgData writeToURL:fileURL atomically:YES]; + + if (cgRef) { + NSBitmapImageRep *newRep = + [[NSBitmapImageRep alloc] initWithCGImage:cgRef]; + NSData *jpgData = [newRep + representationUsingType:NSBitmapImageFileTypeJPEG + properties:@{NSImageCompressionFactor : @0.5f}]; + [jpgData writeToURL:fileURL atomically:YES]; - UNNotificationAttachment *icon = - [UNNotificationAttachment attachmentWithIdentifier:@"art" - URL:fileURL - options:nil - error:&error]; - if (error) { + UNNotificationAttachment *icon = + [UNNotificationAttachment attachmentWithIdentifier:@"art" + URL:fileURL + options:nil + error:&error]; + if (error) { // We have size limit of 10MB per image attachment. - NSLog(@"%@", error.localizedDescription); - } else { - content.attachments = @[ icon ]; + NSLog(@"%@", error.localizedDescription); + } else { + content.attachments = @[ icon ]; + } } } }