-
-
Notifications
You must be signed in to change notification settings - Fork 81
Open
Description
Description
The app crashes on iOS 15 devices when building context menus with UIAction
because the property attributedTitle
does not exist before iOS 16.
Steps to Reproduce
- Open the app on a device running iOS 15.
- Trigger a context menu that sets a custom title color using
attributedTitle
. - The app crashes with
NSUnknownKeyException
.
Crash Log
Fatal Exception: NSUnknownKeyException
[UIAction setValue:forKey:]: this class is not key value coding-compliant for the key attributedTitle
Expected Behavior
- On iOS 15: the menu should still show, falling back to the system default title style.
- On iOS 16+: the title should display with the custom color applied via
attributedTitle
.
Actual Behavior
- App crashes on iOS 15 due to
attributedTitle
being unavailable.
Root Cause
UIAction.attributedTitle
was only introduced in iOS 16.- Using
setValue:forKey:@"attributedTitle"
on iOS 15 leads toNSUnknownKeyException
.
Fix / Suggested Solution
Wrap the code with an iOS availability check:
if (@available(iOS 16.0, *)) {
NSDictionary *attributes = @{NSForegroundColorAttributeName: titleColor};
NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:action.title attributes:attributes];
[actionMenuItem setValue:attributedTitle forKey:@"attributedTitle"];
}
Metadata
Metadata
Assignees
Labels
No labels