-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix crash displaying shields in CarPlay #1665
Conversation
7f6f53e
to
00a0461
Compare
extension NSMutableAttributedString { | ||
func canonicalizeAttachments() { | ||
enumerateAttribute(.attachment, in: NSRange(location: 0, length: length), options: []) { (value, range, stop) in | ||
guard let attachment = value as? NSTextAttachment, type(of: attachment) != NSTextAttachment.self else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@1ec5 this guard... it doesn't read right!!! Would this be why some of the shields are not showing up sometimes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vincethecoder To me, it's reading as "The attachment is a subclass of NSAttachment
, but not the actual class NSAttachment.self
"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JThramer Yes, I'm reading this as we are looking for an attachment which is a subclass of NSTextAttachment
but isn't of type NSTextAttachment
. But I suppose that's why we make the attempt to canonicalize the attachment(s). Btw, is it possible with our attachments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vincethecoder yeah, this is likely because of limitations of the NSAttributedString
logic in CarPlay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The application marshals the attributed string over to the CarPlay simulator or device for rendering. At least for the simulator if not also for the device, the attributed string is marshaled over XPC. It isn’t possible to marshal over instances of our custom NSTextAttachment subclasses, especially not the executable code in these subclasses. “Canonicalizing” the attributed string consists of replacing each subclassed attachment with a plain-vanilla NSTextAttachment that is sure to marshal over correctly.
There are other limitations to attributed strings in CarPlay maneuver instructions, such as being unable to change fonts or font sizes. However, those limitations aren’t limited to CarPlay. For example, on macOS, you can use attributed strings in title bars, but many attributes are ignored.
3c6afcf
to
840349b
Compare
840349b
to
2349138
Compare
Include secondary and tertiary text instructions in plain-text maneuver instructions for CarPlay units that lack support for attributed strings.
Downgrade custom text attachment subclasses to NSTextAttachment before adding them to attributed instructions.
Before adding an attributed string to a maneuver’s attributed instructions, downgrade any instance of a custom text attachment subclass, such as ShieldAttachment, to NSTextAttachment. This ensures that the attributed string can be marshaled over to the CarPlay unit. Unfortunately, even standard NSTextAttachments don’t show up in the CarPlay simulator, but apparently they do show up on an actual CarPlay device.
Along the way, secondary and tertiary text instructions are now included in plain-text maneuver instructions for CarPlay units that lack support for attributed strings.
Fixes #1652.
/cc @JThramer