Skip to content

Instantly share code, notes, and snippets.

@Tunous
Created November 19, 2025 18:07
Show Gist options
  • Select an option

  • Save Tunous/363bb71baa5b401ff8a63304f6389be5 to your computer and use it in GitHub Desktop.

Select an option

Save Tunous/363bb71baa5b401ff8a63304f6389be5 to your computer and use it in GitHub Desktop.
Code to open main app from share extension
// A way to open main app from share extension. Verified on iOS 15-26 and macOS 15
private func openApp() {
// For this to work the app needs to have an url scheme: https://developer.apple.com/documentation/xcode/defining-a-custom-url-scheme-for-your-app
// Potential alternative is also to use universal links: https://developer.apple.com/documentation/xcode/allowing-apps-and-websites-to-link-to-your-content
let url = URL(string: "myApp://")!
#if os(iOS)
if #available(iOS 18.0, *), openURL(url) {
return
}
OpenURLAction.system(url)
#else
NSWorkspace.shared.open(url)
#endif
}
#if os(iOS)
@available(iOS 18, *)
private func openURL(_ url: URL) -> Bool {
let responser = sequence(first: self, next: \.next)
.first(where: { $0 is UIApplication })
if let application = responser as? UIApplication {
application.open(url, options: [:], completionHandler: nil)
return true
}
return false
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment