From fd9a253fac5311c9096c1352f4d8c41eb2b8303b Mon Sep 17 00:00:00 2001 From: CMK Date: Thu, 1 Dec 2022 15:29:56 +0800 Subject: [PATCH] fix: workaround paste crash on iOS 14.x issue --- .../Vendor/MetaTextView+PasteExtensions.swift | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/MastodonSDK/Sources/MastodonUI/Vendor/MetaTextView+PasteExtensions.swift b/MastodonSDK/Sources/MastodonUI/Vendor/MetaTextView+PasteExtensions.swift index 8fe1949af..12e6632a7 100644 --- a/MastodonSDK/Sources/MastodonUI/Vendor/MetaTextView+PasteExtensions.swift +++ b/MastodonSDK/Sources/MastodonUI/Vendor/MetaTextView+PasteExtensions.swift @@ -13,17 +13,21 @@ extension MetaTextView { public override func paste(_ sender: Any?) { super.paste(sender) - var nextResponder = self.next; - - // Force the event to bubble through ALL responders - // This is a workaround as somewhere down the chain the paste event gets eaten - while (nextResponder != nil) { - if let nextResponder = nextResponder { - if (nextResponder.responds(to: #selector(UIResponderStandardEditActions.paste(_:)))) { - nextResponder.perform(#selector(UIResponderStandardEditActions.paste(_:)), with: sender) + // fix #660 + // https://github.com/mastodon/mastodon-ios/issues/660 + if #available(iOS 15.0, *) { + var nextResponder = self.next; + + // Force the event to bubble through ALL responders + // This is a workaround as somewhere down the chain the paste event gets eaten + while (nextResponder != nil) { + if let nextResponder = nextResponder { + if (nextResponder.responds(to: #selector(UIResponderStandardEditActions.paste(_:)))) { + nextResponder.perform(#selector(UIResponderStandardEditActions.paste(_:)), with: sender) + } } + nextResponder = nextResponder?.next; } - nextResponder = nextResponder?.next; - } + } // end if } }