Hello everyone,
I’ve been trying to pass a URL from Safari (or any other app) into my own app via iOS extensions (similar to how if you go to a website, open the share sheet, and hit the ChatGPT app icon, it opens ChatGPT and pastes the website URL into the chat textbox), and I’m hitting a wall. I’ve attempted both a Share Extension (using SLComposeServiceViewController) and a UI-less Action Extension (using extensionContext?.open(...)), but in both scenarios, my main app never opens.
Here’s a summary of my setup:
Main App Target plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>com.elislothower.URLDisplayApp</string>
<key>CFBundleURLSchemes</key>
<array>
<string>myapp</string>
</array>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array/>
</dict>
</plist>
This means my custom URL scheme is myapp://.
My app delegate (or SwiftUI’s .onOpenURL) correctly handles myapp://share?url=... if I open it directly from Safari.
Share Extension Attempt
Subclassed SLComposeServiceViewController.
Plist had com.apple.share-services as the NSExtensionPointIdentifier.
I called extensionContext?.open(deepLink) with myapp://share?url=..., but it always returned false.
Also, the UI (with Cancel/Post buttons) was overkill for my needs.
UI-less Action Extension Attempt
Created a no-UI action extension with com.apple.ui-services as NSExtensionPointIdentifier.
In my custom ActionViewController, I formed the same myapp://share?url=... deep link and called extensionContext?.open(deepLink).
The extension does appear in the share sheet, but again, open(deepLink) returns false—my main app never opens.
Confirmed Setup
I’ve tested the URL scheme in Safari: typing myapp://share?url=... directly prompts to open my app, and the URL is handled fine there.
I’ve ensured both extension Info.plists have <key>LSApplicationQueriesSchemes</key><array><string>myapp</string></array> so they can attempt to open that scheme.
Tried on both simulator and physical device. On the physical device, the main app is definitely installed and has been launched at least once.
Current Behavior
The extension logs that it forms the deep link (myapp://share?url=...) correctly.
extensionContext?.open(deepLink) fails (success == false), so the main app never opens.
I’ve also tried forcing the call on the main thread, simplifying the URL (like myapp://test), and checking for any typos or case-sensitivity issues—still no luck.
Is there a known iOS restriction or trick for allowing an extension (share or action) to open its containing app directly? Have I missed a configuration step or entitlement that’s necessary? Is it possible that iOS is just rejecting the call in these contexts?
I’d love any insight or suggestions from those who have successfully launched their main app from an extension. Thank you in advance!
ContentView.swift
Info.plist
URLDisplayAppApp.swift
URLDisplayApp.entitlements
ActionRequestHandler.swift
ActionViewController.swift
Info.plist
MyAppActionExtension.entitlements
Selecting any option will automatically load the page