From 9f3d258fbd8730ccc1fa58d5dadf1a660f807ed6 Mon Sep 17 00:00:00 2001 From: Eric Jensen Date: Thu, 12 Jan 2023 21:11:16 -0500 Subject: [PATCH 1/4] New URL scheme name variable --- Loop.xcconfig | 3 +++ Loop/Info.plist | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Loop.xcconfig b/Loop.xcconfig index 9c14533902..9e1bb856ae 100644 --- a/Loop.xcconfig +++ b/Loop.xcconfig @@ -45,6 +45,9 @@ LOOP_PROVISIONING_PROFILE_SPECIFIER_WATCHAPP_EXTENSION_RELEASE = // Min iOS Version [DEFAULT] IPHONEOS_DEPLOYMENT_TARGET = 15.1 +// Base string for opening app via URL [DEFAULT] +URL_SCHEME_NAME = $(MAIN_APP_DISPLAY_NAME) + // Version [DEFAULT] #include? "Version.xcconfig" diff --git a/Loop/Info.plist b/Loop/Info.plist index f881313453..75e59c58bc 100644 --- a/Loop/Info.plist +++ b/Loop/Info.plist @@ -31,9 +31,13 @@ CFBundleURLTypes + CFBundleTypeRole + Editor + CFBundleURLName + $(MAIN_APP_BUNDLE_IDENTIFIER) CFBundleURLSchemes - $(MAIN_APP_BUNDLE_IDENTIFIER) + $(URL_SCHEME_NAME) From 5e4730979fc580c9359a25d5974e2dc3fb3317d5 Mon Sep 17 00:00:00 2001 From: Eric Jensen Date: Thu, 12 Jan 2023 22:22:30 -0500 Subject: [PATCH 2/4] Skeleton method to handle deep links. --- Loop/AppDelegate.swift | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Loop/AppDelegate.swift b/Loop/AppDelegate.swift index fb38eda5a2..8de8ceca29 100644 --- a/Loop/AppDelegate.swift +++ b/Loop/AppDelegate.swift @@ -91,4 +91,24 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, WindowProvider { func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { return loopAppManager.supportedInterfaceOrientations } + + // MARK: - UIApplicationDelegate - handle external URLs + + func application(_ application: UIApplication, + open url: URL, + options: [UIApplication.OpenURLOptionsKey : Any] = [:] ) -> Bool { + + // Process the URL. + guard let components = NSURLComponents(url: url, resolvingAgainstBaseURL: true), components.host != "" else { + // No sub-path specified + return true + } + + // Could be a case statement if more than one deep link defined + if components.host == "carbs" { + // Here we would call something like the function presentCarbEntryScreen defined in StatusTableViewController; not sure if that type of code has to all be copied here, or if those various functions (e.g. carb entry, bolus view, settings) should be put elsewhere, or could be repurposed from existing files. + } + return true + } + } From 98845b843203fd1f5a47f87ff62617a7ab34daca Mon Sep 17 00:00:00 2001 From: Eric Jensen Date: Thu, 12 Jan 2023 22:36:19 -0500 Subject: [PATCH 3/4] Add switch statement for various deep link options --- Loop/AppDelegate.swift | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Loop/AppDelegate.swift b/Loop/AppDelegate.swift index 8de8ceca29..1b419b6c7c 100644 --- a/Loop/AppDelegate.swift +++ b/Loop/AppDelegate.swift @@ -99,16 +99,26 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, WindowProvider { options: [UIApplication.OpenURLOptionsKey : Any] = [:] ) -> Bool { // Process the URL. - guard let components = NSURLComponents(url: url, resolvingAgainstBaseURL: true), components.host != "" else { + guard let components = NSURLComponents(url: url, resolvingAgainstBaseURL: true), let linkTarget = components.host else { // No sub-path specified return true } - // Could be a case statement if more than one deep link defined - if components.host == "carbs" { - // Here we would call something like the function presentCarbEntryScreen defined in StatusTableViewController; not sure if that type of code has to all be copied here, or if those various functions (e.g. carb entry, bolus view, settings) should be put elsewhere, or could be repurposed from existing files. + // Below examples would call something like the function presentCarbEntryScreen defined in StatusTableViewController; not sure if that type of code has to all be copied here, or if those various functions (e.g. carb entry, bolus view, settings) should be put elsewhere, or could be repurposed from existing files. + + switch linkTarget.lowercased() { + case "carbs" : + // open carb entry view controller + return true + case "bolus" : + // open bolus view controller + return true + case "settings" : + // open settings view + return true + default : + return true } - return true } } From 7638f864fe206bfe55d9b4bc48c9570c98647fa7 Mon Sep 17 00:00:00 2001 From: Eric Jensen Date: Fri, 20 Jan 2023 22:01:09 -0500 Subject: [PATCH 4/4] Remove code for parsing URL path --- Loop/AppDelegate.swift | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/Loop/AppDelegate.swift b/Loop/AppDelegate.swift index 1b419b6c7c..fb38eda5a2 100644 --- a/Loop/AppDelegate.swift +++ b/Loop/AppDelegate.swift @@ -91,34 +91,4 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, WindowProvider { func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { return loopAppManager.supportedInterfaceOrientations } - - // MARK: - UIApplicationDelegate - handle external URLs - - func application(_ application: UIApplication, - open url: URL, - options: [UIApplication.OpenURLOptionsKey : Any] = [:] ) -> Bool { - - // Process the URL. - guard let components = NSURLComponents(url: url, resolvingAgainstBaseURL: true), let linkTarget = components.host else { - // No sub-path specified - return true - } - - // Below examples would call something like the function presentCarbEntryScreen defined in StatusTableViewController; not sure if that type of code has to all be copied here, or if those various functions (e.g. carb entry, bolus view, settings) should be put elsewhere, or could be repurposed from existing files. - - switch linkTarget.lowercased() { - case "carbs" : - // open carb entry view controller - return true - case "bolus" : - // open bolus view controller - return true - case "settings" : - // open settings view - return true - default : - return true - } - } - }