skip to Main Content

I’m new to swift and I’m struggling to redirect from the share extension to the main application, I want to extract the image’s url and then use that in the main application.

I’ve tried instantiating the storyboard once I’ve got my url, but I can’t since they aren’t in the same target.

2

Answers


  1. Please select the file and add it to your target.
    enter image description here

    Login or Signup to reply.
  2. you can use openURL: to send the url from share extension to the main application.

    call this function in view controller in share extension

    func openContainerApp(with url: URL) async {
        guard let items = self.extensionContext?.inputItems as? [NSExtensionItem], !items.isEmpty else {
            return
        }
    
        defer {
            extensionContext?.completeRequest(returningItems: nil, completionHandler: nil)
        }
    
        let selector = sel_registerName("openURL:")
    
        var responder = self as UIResponder?
        while responder != nil {
            if responder!.responds(to: selector) {
                responder!.perform(selector, with: url)
                break
            }
            responder = responder?.next
        }
    }
    

    and main application can receive the url in app delegate func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search