From 012af05ab8a26e34d99eb619ab58ef7dd07e5646 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Mon, 13 Jun 2022 20:52:40 -0500 Subject: [PATCH] Add universal links (iOS) --- ios/Podfile | 1 + ios/Podfile.lock | 2 +- ios/app.xcodeproj/project.pbxproj | 22 +++++++++++++------ .../xcshareddata/xcschemes/app.xcscheme | 2 +- .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++++ ios/app/AppDelegate.mm | 18 +++++++++++++++ ios/app/Info.plist | 2 +- ios/app/app.entitlements | 10 +++++++++ src/routes/index.tsx | 15 +++++++++++-- 9 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 ios/app.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 ios/app/app.entitlements diff --git a/ios/Podfile b/ios/Podfile index 7fe4b5644a..5991f646db 100644 --- a/ios/Podfile +++ b/ios/Podfile @@ -5,6 +5,7 @@ platform :ios, '11.0' install! 'cocoapods', :deterministic_uuids => false target 'app' do + pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS' config = use_native_modules! # Flags change depending on the env values. diff --git a/ios/Podfile.lock b/ios/Podfile.lock index fef825bb55..e03120fe44 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -562,6 +562,6 @@ SPEC CHECKSUMS: Yoga: 99652481fcd320aefa4a7ef90095b95acd181952 YogaKit: f782866e155069a2cca2517aafea43200b01fd5a -PODFILE CHECKSUM: e7829ab2918d1c9b033dd087443b49c3a19ca424 +PODFILE CHECKSUM: 62c8e2b4f24d75700d9ebdf33d58c769c1fcc7b5 COCOAPODS: 1.11.3 diff --git a/ios/app.xcodeproj/project.pbxproj b/ios/app.xcodeproj/project.pbxproj index 6705983581..30b0862702 100644 --- a/ios/app.xcodeproj/project.pbxproj +++ b/ios/app.xcodeproj/project.pbxproj @@ -43,6 +43,7 @@ 5DCACB8F33CDC322A6C60F78 /* libPods-app.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-app.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = app/LaunchScreen.storyboard; sourceTree = ""; }; 89C6BE57DB24E9ADA2F236DE /* Pods-app-appTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-app-appTests.release.xcconfig"; path = "Target Support Files/Pods-app-appTests/Pods-app-appTests.release.xcconfig"; sourceTree = ""; }; + E4437C9E28581FA7006DA9E7 /* app.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = app.entitlements; path = app/app.entitlements; sourceTree = ""; }; ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; /* End PBXFileReference section */ @@ -86,6 +87,7 @@ 13B07FAE1A68108700A75B9A /* app */ = { isa = PBXGroup; children = ( + E4437C9E28581FA7006DA9E7 /* app.entitlements */, 13B07FAF1A68108700A75B9A /* AppDelegate.h */, 13B07FB01A68108700A75B9A /* AppDelegate.mm */, 13B07FB51A68108700A75B9A /* Images.xcassets */, @@ -200,7 +202,7 @@ 83CBB9F71A601CBA00E9B192 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1210; + LastUpgradeCheck = 1340; TargetAttributes = { 00E356ED1AD99517003FC87E = { CreatedOnToolsVersion = 6.2; @@ -430,13 +432,14 @@ isa = XCBuildConfiguration; baseConfigurationReference = 5B7EB9410499542E8C5724F5 /* Pods-app-appTests.debug.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", ); INFOPLIST_FILE = appTests/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -457,10 +460,11 @@ isa = XCBuildConfiguration; baseConfigurationReference = 89C6BE57DB24E9ADA2F236DE /* Pods-app-appTests.release.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; COPY_PHASE_STRIP = NO; INFOPLIST_FILE = appTests/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -483,7 +487,9 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = app/app.entitlements; CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = A6GRZHF6BV; ENABLE_BITCODE = NO; INFOPLIST_FILE = app/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( @@ -495,7 +501,7 @@ "-ObjC", "-lc++", ); - PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_BUNDLE_IDENTIFIER = xyz.blueskyweb.pubsq; PRODUCT_NAME = app; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; @@ -509,7 +515,9 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = app/app.entitlements; CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = A6GRZHF6BV; INFOPLIST_FILE = app/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -520,7 +528,7 @@ "-ObjC", "-lc++", ); - PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_BUNDLE_IDENTIFIER = xyz.blueskyweb.pubsq; PRODUCT_NAME = app; SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; @@ -576,7 +584,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = ( /usr/lib/swift, "$(inherited)", @@ -640,7 +648,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = ( /usr/lib/swift, "$(inherited)", diff --git a/ios/app.xcodeproj/xcshareddata/xcschemes/app.xcscheme b/ios/app.xcodeproj/xcshareddata/xcschemes/app.xcscheme index 9b78d17732..326123a327 100644 --- a/ios/app.xcodeproj/xcshareddata/xcschemes/app.xcscheme +++ b/ios/app.xcodeproj/xcshareddata/xcschemes/app.xcscheme @@ -1,6 +1,6 @@ + + + + IDEDidComputeMac32BitWarning + + + diff --git a/ios/app/AppDelegate.mm b/ios/app/AppDelegate.mm index 27cde7ef81..8b143fee24 100644 --- a/ios/app/AppDelegate.mm +++ b/ios/app/AppDelegate.mm @@ -6,6 +6,9 @@ #import +// universal links +#import + #if RCT_NEW_ARCH_ENABLED #import #import @@ -105,4 +108,19 @@ #endif +// universal links +- (BOOL)application:(UIApplication *)application + openURL:(NSURL *)url + options:(NSDictionary *)options +{ + return [RCTLinkingManager application:application openURL:url options:options]; +} + +- (BOOL)application:(UIApplication *)application + continueUserActivity:(nonnull NSUserActivity *)userActivity + restorationHandler:(nonnull void (^)(NSArray> * _Nullable))restorationHandler +{ + return [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler]; +} + @end diff --git a/ios/app/Info.plist b/ios/app/Info.plist index bbafb8bc41..fca6902c2e 100644 --- a/ios/app/Info.plist +++ b/ios/app/Info.plist @@ -5,7 +5,7 @@ CFBundleDevelopmentRegion en CFBundleDisplayName - app + PubSQ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier diff --git a/ios/app/app.entitlements b/ios/app/app.entitlements new file mode 100644 index 0000000000..ad10c10e5a --- /dev/null +++ b/ios/app/app.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.developer.associated-domains + + applinks:pubsq.pfrazee.com + + + diff --git a/src/routes/index.tsx b/src/routes/index.tsx index a8a92e54fc..5084473ec5 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -1,5 +1,5 @@ -import React from 'react' -import {Text} from 'react-native' +import React, {useEffect} from 'react' +import {Text, Linking} from 'react-native' import { NavigationContainer, LinkingOptions, @@ -24,6 +24,7 @@ import {NotFound} from '../screens/NotFound' const linking: LinkingOptions = { prefixes: [ 'http://localhost:3000', // local dev + 'https://pubsq.pfrazee.com', // test server (universal links only) ], config: { screens: { @@ -59,6 +60,16 @@ const HIDE_TAB = {tabBarButton: () => null} export const Root = observer(() => { const store = useStores() + useEffect(() => { + console.log('Initial link setup') + Linking.getInitialURL().then((url: string | null) => { + console.log('Initial url', url) + }) + Linking.addEventListener('url', ({url}) => { + console.log('Deep link opened with', url) + }) + }, []) + // hide the tabbar on desktop web const tabBar = platform.isDesktopWeb ? () => null : undefined