From e2cede8e3d902ef33c06e335d25705b917df71f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Poizat?= Date: Thu, 17 Oct 2024 18:37:06 +0200 Subject: [PATCH] feat: Update ShareViewController to support iOS 18 Not linked to RN0.73 but to iOS 18. Solution inspired from https://github.com/ajith-ab/react-native-receive-sharing-intent/issues/185#issuecomment-2407291651 --- ios/CozyShare/ShareViewController.swift | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/ios/CozyShare/ShareViewController.swift b/ios/CozyShare/ShareViewController.swift index 8fda796a9..34230c2b8 100644 --- a/ios/CozyShare/ShareViewController.swift +++ b/ios/CozyShare/ShareViewController.swift @@ -4,6 +4,7 @@ import Social import MobileCoreServices import Photos +@available(iOSApplicationExtension, unavailable) class ShareViewController: UIViewController { let hostAppBundleIdentifier = "io.cozy.flagship.mobile" let shareProtocol = "cozyShare" @@ -188,19 +189,19 @@ class ShareViewController: UIViewController { extensionContext!.completeRequest(returningItems: [], completionHandler: nil) } - private func redirectToHostApp(type: RedirectType) { - let url = URL(string: "\(shareProtocol)://dataUrl=\(sharedKey)#\(type)") - var responder = self as UIResponder? - let selectorOpenURL = sel_registerName("openURL:") + // Changed from package readme because https://github.com/ajith-ab/react-native-receive-sharing-intent/issues/185#issuecomment-2407291651 + private func redirectToHostApp(type: RedirectType) { + guard let url = URL(string: "\(shareProtocol)://dataUrl=\(sharedKey)#\(type)") else { + dismissWithError() + return //be safe + } - while (responder != nil) { - if (responder?.responds(to: selectorOpenURL))! { - let _ = responder?.perform(selectorOpenURL, with: url) - } - responder = responder!.next - } - extensionContext!.completeRequest(returningItems: [], completionHandler: nil) - } + UIApplication.shared.open(url, options: [:], completionHandler: completeRequest) + } + + func completeRequest(success: Bool) { + extensionContext!.completeRequest(returningItems: [], completionHandler: nil) + } enum RedirectType { case media