achorein / expo-share-intent

🚀 Simple share intent in an Expo Native Module
MIT License
177 stars 15 forks source link

URL sharing doesn't work on iOS 18 #105

Closed darix795 closed 1 week ago

darix795 commented 2 weeks ago

Describe the bug Yesterday I upgraded Xcode to version 16 and try to run my app on iOS 18, but seems that when I share urls to my app controller is showed but app isn't opened. When I try on simulator with iOS 17 everything works fine.

To Reproduce Try on iOS 18 and that's it

https://github.com/user-attachments/assets/69d43884-afba-4418-b60d-ed1597ce352a

Environment System: OS: macOS 14.6.1 CPU: (10) arm64 Apple M1 Pro Memory: 418.08 MB / 32.00 GB Shell: version: "5.9" path: /bin/zsh Binaries: Node: version: 20.17.0 path: ~/.nvm/versions/node/v20.17.0/bin/node Yarn: version: 1.22.22 path: ~/.nvm/versions/node/v20.17.0/bin/yarn npm: version: 10.8.2 path: ~/.nvm/versions/node/v20.17.0/bin/npm Watchman: version: 2024.08.26.00 path: /opt/homebrew/bin/watchman Managers: CocoaPods: version: 1.15.2 path: /opt/homebrew/lib/ruby/gems/3.1.0/bin/pod SDKs: iOS SDK: Platforms:

achorein commented 2 weeks ago

:/ any error in console or xcode logs ?

mfkrause commented 2 weeks ago

This is likely due to this function: https://github.com/achorein/expo-share-intent/blob/1c41e641bc1e6c91999d10ba63477ab9f254430f/plugin/src/ios/ShareExtensionViewController.swift#L251-L269

In line 254, you're using an openURL selector on UIResponder. This has been deprecated for quite a while (past iOS 10) and has now been completely disabled in the iOS 18 SDK:

However, it's not as simple as changing the selector in line 254 to i.e. open:options:completionHandler:. Here's a write-up on a similar issue in the KeyboardKit SwiftUI SDK (unrelated package, but the issue is effectively the same).

Unfortunately, I currently don't have the time to propose a fix, but just wanted to leave this here in case it helps. For now, you'll need to build with the iOS 17 SDK / Xcode 15. If you do, the share extension will work fine in iOS 18, too. Currently, the Expo EAS cloud still uses Xcode 15, therefore it works fine if you build the app using EAS Cloud (once they switch to Xcode 16 / iOS 18 SDK, you might be able to force the old Xcode / SDK by using the macos-sonoma-14.5-xcode-15.4 server image).

cback97 commented 2 weeks ago

getting this same error when sharing an image, probably related.

achorein commented 2 weeks ago

I will check xcode16 and ios18 issues next week.

darix795 commented 2 weeks ago

Ok, i tried to reproduce error in this repo and I solved by replacing SLComposeServiceViewController extension to UIViewController and application.perform(selectorOpenURL, with: url) with application.open(url) in according with Apple's offical docs.

- class ShareViewController: SLComposeServiceViewController
+ class ShareViewController: UIViewController
- let selectorOpenURL = sel_registerName("openURL:")
- application.perform(selectorOpenURL, with: url) 
+ application.open(url)

After this changes it seems to works fine on Xcode 16 and iOS 18. I was tested with links, files and images. Unfortunately, i haven't permission to open new pull requests.

achorein commented 2 weeks ago

@darix795 thank you for digging this, i'm going to to test this on my own. btw you can fork this repo and make a PR from it.

achorein commented 1 week ago

@darix795 Fixed in v2.4.0