Fix getAppIcon() crash on iOS 26 Simulator

UIImage(named:) can raise NSInternalInconsistencyException ("Need an
imageRef") for app icon assets that can't be rasterized for the current
trait, bypassing Swift's optional-based error handling. Wrap the call in
PulseObjCExceptionCatcher via a new reusable `attempt` helper.

Fixes #364.
This commit is contained in:
Alex Grebenyuk
2026-04-20 19:16:15 -04:00
parent e1c7f83198
commit 14383871aa
3 changed files with 17 additions and 1 deletions
+6
View File
@@ -1,5 +1,11 @@
# Pulse 5.x
## Pulse 5.2.1
*Apr 20, 2026*
- Fix a crash on iOS 26 Simulator where `UIImage(named:)` raises `NSInternalInconsistencyException` ("Need an imageRef") for app icon assets that can't be rasterized for the current trait ([#364](https://github.com/kean/Pulse/issues/364))
## Pulse 5.2
*Apr 19, 2026*
@@ -15,6 +15,13 @@ extension PulseObjCExceptionCatcher {
}
return try result!.get()
}
/// Returns the result of `block`, or `nil` if it returns `nil` or raises
/// an Objective-C exception. Useful for UIKit APIs that raise exceptions
/// from otherwise-optional call sites (e.g. `UIImage(named:)` on iOS 26+).
public static func attempt<T>(_ block: () -> T?) -> T? {
(try? perform(block)) ?? nil
}
}
extension NSManagedObjectContext {
@@ -3,6 +3,7 @@
// Copyright (c) 2020-2026 Alexander Grebenyuk (github.com/kean).
import Foundation
import PulseObjCHelpers
extension LoggerStore {
/// The store info.
@@ -93,7 +94,9 @@ private func getAppIcon() -> Data? {
let primaryIcons = icons["CFBundlePrimaryIcon"] as? [String: Any],
let files = primaryIcons["CFBundleIconFiles"] as? [String],
let lastIcon = files.last,
let image = PlatformImage(named: lastIcon),
// On iOS 26+, `UIImage(named:)` can raise `NSInternalInconsistencyException`
// ("Need an imageRef") for assets that can't be rasterized for the current trait.
let image = PulseObjCExceptionCatcher.attempt({ PlatformImage(named: lastIcon) }),
let thumbnail = Graphics.resize(image, to: CGSize(width: 44, height: 44)) else { return nil }
return Graphics.encode(thumbnail, compressionQuality: 0.9)
}