Description
tldr: solution at bottom
I had set this extension up originally for my app running iOS 17.
I did it a tiny bit different than what the docs suggested just because all I wanted to was be able to open Safari, click share, select my app, and it receive the URL from Safari. For this I basically used the same ShareViewController
file but modified it slightly. More on this here.
Anyway, I noticed after I upgraded my device to iOS 18, nothing would happen after clicking my app in the share sheet. It still shows up but nothing happened.
Turns out the issue was that an underlining function, openUrl
, called in ShareViewController
has been deprecated and I guess fully removed in iOS 18. I was getting this error when I debugged my extension in XCode:
BUG IN CLIENT OF UIKIT: The caller of UIApplication.openURL(_:) needs to migrate to the non-deprecated
Solution
To fix this, I did a few things.
// ...
import UIKit
import Social
import RNShareMenu
+@available(iOSApplicationExtension, unavailable)
+
class ShareViewController: UIViewController {
var hostAppId: String?
var hostAppUrlScheme: String?
// ..
internal func openHostApp() {
guard let urlScheme = self.hostAppUrlScheme else {
exit(withError: NO_INFO_PLIST_URL_SCHEME_ERROR)
return
}
+
+ guard let url = URL(string: urlScheme) else {
+ exit(withError: NO_INFO_PLIST_URL_SCHEME_ERROR)
+ return //be safe
+ }
+
+ UIApplication.shared.open(url, options: [:], completionHandler: completeRequest)
-
- let url = URL(string: urlScheme)
- let selectorOpenURL = sel_registerName("openURL:")
- var responder: UIResponder? = self
-
- while responder != nil {
- if responder?.responds(to: selectorOpenURL) == true {
- responder?.perform(selectorOpenURL, with: url)
- }
- responder = responder!.next
- completeRequest()
}
- func completeRequest() {
+ func completeRequest(success: Bool) {
// Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context.
extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
}
func cancelRequest() {
extensionContext!.cancelRequest(withError: NSError())
}
}
This works for me. Opening the app is now powered by this function. Apparently this function has been supported since iOS 10 so I see no reason to add any version specific code.
I am in no way a swift developer. I just poked around until it worked. If anyone is, please provide feedback.
Hope this helps someone!