Skip to content

Commit

Permalink
feat: Update ShareViewController to support iOS 18
Browse files Browse the repository at this point in the history
Not linked to RN0.73 but to iOS 18. Solution inspired from
ajith-ab/react-native-receive-sharing-intent#185 (comment)
  • Loading branch information
zatteo committed Oct 22, 2024
1 parent 5610edf commit ac7516b
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions ios/CozyShare/ShareViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ac7516b

Please sign in to comment.