diff --git a/.changeset/ios-scene-warm-links.md b/.changeset/ios-scene-warm-links.md new file mode 100644 index 000000000..f4a52b1ab --- /dev/null +++ b/.changeset/ios-scene-warm-links.md @@ -0,0 +1,5 @@ +--- +'@callstack/react-native-brownfield': patch +--- + +Deliver deep links and universal links that arrive while the app is running in iOS hosts that declare `UISceneConfigurations`. React Native 0.88 ignores `RCTLinkingManager`'s app delegate entry points in such apps, so the `Linking` `url` event never fired. diff --git a/apps/AppleApp/Brownfield Apple App.xcodeproj/project.pbxproj b/apps/AppleApp/Brownfield Apple App.xcodeproj/project.pbxproj index 7709cb2c8..bf5256582 100644 --- a/apps/AppleApp/Brownfield Apple App.xcodeproj/project.pbxproj +++ b/apps/AppleApp/Brownfield Apple App.xcodeproj/project.pbxproj @@ -632,8 +632,6 @@ ENABLE_USER_SELECTED_FILES = readonly; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist"; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; @@ -679,8 +677,6 @@ ENABLE_USER_SELECTED_FILES = readonly; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist"; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; @@ -726,8 +722,6 @@ ENABLE_USER_SELECTED_FILES = readonly; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist"; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; @@ -773,8 +767,6 @@ ENABLE_USER_SELECTED_FILES = readonly; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist"; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; @@ -938,8 +930,6 @@ ENABLE_USER_SELECTED_FILES = readonly; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist"; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; @@ -985,8 +975,6 @@ ENABLE_USER_SELECTED_FILES = readonly; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist"; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; @@ -1032,8 +1020,6 @@ ENABLE_USER_SELECTED_FILES = readonly; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist"; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; @@ -1079,8 +1065,6 @@ ENABLE_USER_SELECTED_FILES = readonly; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist"; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; @@ -1126,8 +1110,6 @@ ENABLE_USER_SELECTED_FILES = readonly; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist"; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; @@ -1173,8 +1155,6 @@ ENABLE_USER_SELECTED_FILES = readonly; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist"; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; @@ -1338,8 +1318,6 @@ ENABLE_USER_SELECTED_FILES = readonly; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist"; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; @@ -1385,8 +1363,6 @@ ENABLE_USER_SELECTED_FILES = readonly; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist"; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; @@ -1432,8 +1408,6 @@ ENABLE_USER_SELECTED_FILES = readonly; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist"; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; @@ -1479,8 +1453,6 @@ ENABLE_USER_SELECTED_FILES = readonly; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist"; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; @@ -1526,8 +1498,6 @@ ENABLE_USER_SELECTED_FILES = readonly; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist"; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; @@ -1573,8 +1543,6 @@ ENABLE_USER_SELECTED_FILES = readonly; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist"; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; - "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; diff --git a/apps/AppleApp/Brownfield Apple App/BrownfieldAppleApp.swift b/apps/AppleApp/Brownfield Apple App/BrownfieldAppleApp.swift index 1b8f25805..a5ff75d01 100644 --- a/apps/AppleApp/Brownfield Apple App/BrownfieldAppleApp.swift +++ b/apps/AppleApp/Brownfield Apple App/BrownfieldAppleApp.swift @@ -152,6 +152,16 @@ struct BrownfieldAppleApp: App { var body: some Scene { WindowGroup { RootContentView(appDelegate: appDelegate) + .onOpenURL { url in + _ = ReactNativeBrownfield.shared.application(UIApplication.shared, open: url) + } + .onContinueUserActivity(NSUserActivityTypeBrowsingWeb) { userActivity in + _ = ReactNativeBrownfield.shared.application( + UIApplication.shared, + continue: userActivity, + restorationHandler: { _ in } + ) + } } } } diff --git a/apps/AppleApp/Brownfield-Apple-App-Info.plist b/apps/AppleApp/Brownfield-Apple-App-Info.plist index 0c67376eb..68d01a668 100644 --- a/apps/AppleApp/Brownfield-Apple-App-Info.plist +++ b/apps/AppleApp/Brownfield-Apple-App-Info.plist @@ -1,5 +1,32 @@ - + + CFBundleURLTypes + + + CFBundleURLName + com.callstack.brownfield.ios.example + CFBundleURLSchemes + + brownfield-apple-app + + + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + + + + + diff --git a/apps/brownfield-example-shared-tests/e2e/appleAppDetoxUtils.cjs b/apps/brownfield-example-shared-tests/e2e/appleAppDetoxUtils.cjs index b2f72b75f..dc05ce61a 100644 --- a/apps/brownfield-example-shared-tests/e2e/appleAppDetoxUtils.cjs +++ b/apps/brownfield-example-shared-tests/e2e/appleAppDetoxUtils.cjs @@ -1,4 +1,5 @@ -const { device, element, by, expect: detoxExpect } = require('detox'); +const { execFileSync } = require('node:child_process'); +const { device, element, by, system, expect: detoxExpect } = require('detox'); const { brownfieldE2ETestIds: ids, } = require('@callstack/brownfield-example-shared-tests/e2e/e2eTestIds'); @@ -222,6 +223,41 @@ async function sendPostMessageToNativeAndWaitForToast() { ); } +/** + * Open `url` in the running app the way the system does, so it arrives through the + * scene (`scene(_:openURLContexts:)`) rather than a call Detox makes on the app delegate. + * The simulator may ask before handing a custom-scheme URL to an app; accept that prompt + * when it shows up. + */ +async function openURLThroughSystem(url) { + execFileSync('xcrun', ['simctl', 'openurl', device.id, url]); + await acceptOpenURLPromptIfShown(); +} + +async function acceptOpenURLPromptIfShown() { + const openButton = by.system.label('Open'); + const deadline = Date.now() + DETOX_TIMING.OPEN_URL_PROMPT_TIMEOUT_MS; + let lastError; + while (Date.now() < deadline) { + try { + await system.element(openButton).tap(); + return; + } catch (error) { + lastError = error; + await new Promise((resolve) => + setTimeout(resolve, DETOX_TIMING.POLL_INTERVAL_MS) + ); + } + } + console.warn( + `[AppleApp] No "Open" prompt accepted after opening a URL: ${lastError?.message ?? 'no attempt made'}` + ); +} + +async function waitForExploreTabExpo() { + await waitForExpoMatcher(by.text('Expo documentation')); +} + module.exports = { detoxLaunchArgs, waitForAppleAppReady, @@ -229,5 +265,7 @@ module.exports = { openReactNativeExpo, openHomeTabExpo, openPostMessageTabExpo, + openURLThroughSystem, + waitForExploreTabExpo, sendPostMessageToNativeAndWaitForToast, }; diff --git a/apps/brownfield-example-shared-tests/e2e/appleAppExpoBrownfield.e2e.js b/apps/brownfield-example-shared-tests/e2e/appleAppExpoBrownfield.e2e.js index f02bc7dfd..f231596c8 100644 --- a/apps/brownfield-example-shared-tests/e2e/appleAppExpoBrownfield.e2e.js +++ b/apps/brownfield-example-shared-tests/e2e/appleAppExpoBrownfield.e2e.js @@ -10,6 +10,8 @@ const { waitForAppleAppReady, openHomeTabExpo, openPostMessageTabExpo, + openURLThroughSystem, + waitForExploreTabExpo, sendPostMessageToNativeAndWaitForToast, } = require('@callstack/brownfield-example-shared-tests/e2e/appleAppDetoxUtils'); @@ -26,6 +28,12 @@ describe('Brownfield (AppleApp — Expo)', () => { await openHomeTabExpo(); }); + it('routes a deep link that arrives while the app is running', async () => { + await openHomeTabExpo(); + await openURLThroughSystem('brownfield-apple-app://explore'); + await waitForExploreTabExpo(); + }); + it('shows a native toast when Expo RN sends postMessage', async () => { await openPostMessageTabExpo(); await sendPostMessageToNativeAndWaitForToast(); diff --git a/apps/brownfield-example-shared-tests/e2e/detoxTiming.cjs b/apps/brownfield-example-shared-tests/e2e/detoxTiming.cjs index c140b41f5..141f3afb6 100644 --- a/apps/brownfield-example-shared-tests/e2e/detoxTiming.cjs +++ b/apps/brownfield-example-shared-tests/e2e/detoxTiming.cjs @@ -14,6 +14,9 @@ const DETOX_TIMING = { /** Timeout for the visibility of toasts. */ TOAST_VISIBILITY_TIMEOUT_MS: 60_000, + /** How long to wait for the system "Open in ...?" prompt after opening a URL. */ + OPEN_URL_PROMPT_TIMEOUT_MS: 5_000, + /** Timeout for the entire E2E test suite (detox + Jest + Maestro). */ TEST_TIMEOUT_MS: 720_000, }; diff --git a/packages/react-native-brownfield/ios/BrownfieldLinking.swift b/packages/react-native-brownfield/ios/BrownfieldLinking.swift new file mode 100644 index 000000000..76664c044 --- /dev/null +++ b/packages/react-native-brownfield/ios/BrownfieldLinking.swift @@ -0,0 +1,47 @@ +import UIKit +internal import React + +enum BrownfieldLinking { + private static let openURLNotification = Notification.Name("RCTOpenURLNotification") + + static func open( + _ app: UIApplication, + url: URL, + options: [UIApplication.OpenURLOptionsKey: Any] + ) -> Bool { + if RCTLinkingManager.application(app, open: url, options: options) { + return true + } + postOpenURLNotification(url) + return true + } + + static func continueUserActivity( + _ application: UIApplication, + userActivity: NSUserActivity, + restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void + ) -> Bool { + if RCTLinkingManager.application( + application, + continue: userActivity, + restorationHandler: restorationHandler + ) { + return true + } + guard userActivity.activityType == NSUserActivityTypeBrowsingWeb, + let url = userActivity.webpageURL + else { + return false + } + postOpenURLNotification(url) + return true + } + + private static func postOpenURLNotification(_ url: URL) { + NotificationCenter.default.post( + name: openURLNotification, + object: nil, + userInfo: ["url": url.absoluteString] + ) + } +} diff --git a/packages/react-native-brownfield/ios/Expo/ExpoHostRuntime.swift b/packages/react-native-brownfield/ios/Expo/ExpoHostRuntime.swift index 194fa7c95..a8469c8b9 100644 --- a/packages/react-native-brownfield/ios/Expo/ExpoHostRuntime.swift +++ b/packages/react-native-brownfield/ios/Expo/ExpoHostRuntime.swift @@ -158,7 +158,7 @@ final class ExpoHostRuntime { open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:] ) -> Bool { - return (expoDelegate?.application(app, open: url, options: options) ?? false) || RCTLinkingManager.application(app, open: url, options: options) + return (expoDelegate?.application(app, open: url, options: options) ?? false) || BrownfieldLinking.open(app, url: url, options: options) } // Universal Links; base implementation courtesy of Expo, licensed under the MIT License - changes were made to call the method on expo delegate - https://github.com/expo/expo/blob/main/apps/bare-expo/ios/AppDelegate.swift @@ -167,7 +167,7 @@ final class ExpoHostRuntime { continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void ) -> Bool { - let result = RCTLinkingManager.application(application, continue: userActivity, restorationHandler: restorationHandler) + let result = BrownfieldLinking.continueUserActivity(application, userActivity: userActivity, restorationHandler: restorationHandler) return (expoDelegate?.application(application, continue: userActivity, restorationHandler: restorationHandler) ?? false) || result } diff --git a/packages/react-native-brownfield/ios/Vanilla/ReactNativeHostRuntime.swift b/packages/react-native-brownfield/ios/Vanilla/ReactNativeHostRuntime.swift index 2e74b870d..016db95e7 100644 --- a/packages/react-native-brownfield/ios/Vanilla/ReactNativeHostRuntime.swift +++ b/packages/react-native-brownfield/ios/Vanilla/ReactNativeHostRuntime.swift @@ -175,7 +175,7 @@ final class ReactNativeHostRuntime { open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:] ) -> Bool { - return RCTLinkingManager.application(app, open: url, options: options) + return BrownfieldLinking.open(app, url: url, options: options) } public func application( @@ -183,7 +183,7 @@ final class ReactNativeHostRuntime { continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void ) -> Bool { - return RCTLinkingManager.application(application, continue: userActivity, restorationHandler: restorationHandler) + return BrownfieldLinking.continueUserActivity(application, userActivity: userActivity, restorationHandler: restorationHandler) } /**