From 97960548708de502beab0a58e3ed40fdccd9dce2 Mon Sep 17 00:00:00 2001 From: "Thakur, Abhishek" Date: Fri, 17 Jan 2025 17:37:51 -0600 Subject: [PATCH] Update the sample to use the latest release of the CIQ Companion app SDK version 1.6.0 Updated to use the latest release of the SDK which includes changes to support Universal Links to launch the companion app when fetching paired devices from the Garmin Connect app. Companion app now can send transient messages using the sendMessage() API. --- ExampleApp/ExampleApp.xcodeproj/project.pbxproj | 15 +++++++++------ .../xcshareddata/swiftpm/Package.resolved | 7 ++++--- ExampleApp/ExampleApp/AppDelegate.m | 14 +++++++++++++- ExampleApp/ExampleApp/AppMessageViewController.m | 2 +- ExampleApp/ExampleApp/Constants.h | 1 + ExampleApp/ExampleApp/Constants.m | 1 + ExampleApp/ExampleApp/DeviceManager.m | 2 +- ExampleApp/ExampleApp/ExampleApp.entitlements | 10 ++++++++++ 8 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 ExampleApp/ExampleApp/ExampleApp.entitlements diff --git a/ExampleApp/ExampleApp.xcodeproj/project.pbxproj b/ExampleApp/ExampleApp.xcodeproj/project.pbxproj index 4aab18a..1dc30b1 100644 --- a/ExampleApp/ExampleApp.xcodeproj/project.pbxproj +++ b/ExampleApp/ExampleApp.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 52; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -66,6 +66,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 95121AC72CCA97E000DA53EC /* ExampleApp.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = ExampleApp.entitlements; sourceTree = ""; }; D6054E271A64792F0029113F /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/InfoPlist.strings; sourceTree = ""; }; D6054E281A64792F0029113F /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/InfoPlist.strings; sourceTree = ""; }; D60D04A8199E546C00870EDC /* ExampleApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ExampleApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -216,6 +217,7 @@ D60D04B1199E546C00870EDC /* ExampleApp */ = { isa = PBXGroup; children = ( + 95121AC72CCA97E000DA53EC /* ExampleApp.entitlements */, D60D04BA199E546C00870EDC /* AppDelegate.h */, D60D04BB199E546C00870EDC /* AppDelegate.m */, D65B41A919F98B4800D9E655 /* Constants.h */, @@ -361,9 +363,6 @@ LastUpgradeCheck = 1130; ORGANIZATIONNAME = Garmin; TargetAttributes = { - D60D04A7199E546C00870EDC = { - DevelopmentTeam = 72ES32VZUA; - }; D60D04C8199E546D00870EDC = { TestTargetID = D60D04A7199E546C00870EDC; }; @@ -661,8 +660,10 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_ENTITLEMENTS = ExampleApp/ExampleApp.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + DEVELOPMENT_TEAM = ""; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(SRCROOT)/..", @@ -676,7 +677,7 @@ "@executable_path/Frameworks", ); OTHER_LDFLAGS = "-ObjC"; - PRODUCT_BUNDLE_IDENTIFIER = "com.garmin.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_BUNDLE_IDENTIFIER = com.garmin.connectiqsdk.ExampleApp; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; WRAPPER_EXTENSION = app; @@ -687,8 +688,10 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_ENTITLEMENTS = ExampleApp/ExampleApp.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + DEVELOPMENT_TEAM = ""; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(SRCROOT)/..", @@ -702,7 +705,7 @@ "@executable_path/Frameworks", ); OTHER_LDFLAGS = "-ObjC"; - PRODUCT_BUNDLE_IDENTIFIER = "com.garmin.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_BUNDLE_IDENTIFIER = com.garmin.connectiqsdk.ExampleApp; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; WRAPPER_EXTENSION = app; diff --git a/ExampleApp/ExampleApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ExampleApp/ExampleApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 54133a1..143de15 100644 --- a/ExampleApp/ExampleApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ExampleApp/ExampleApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,14 +1,15 @@ { + "originHash" : "8546cec043655f015797511747e9dcac32fc6a266541bb73e85a63ae4956b656", "pins" : [ { "identity" : "connectiq-companion-app-sdk-ios", "kind" : "remoteSourceControl", "location" : "https://github.com/garmin/connectiq-companion-app-sdk-ios", "state" : { - "revision" : "d61f5b7ddb93c20a2ee2dfc67aea91fe21b66da1", - "version" : "1.5.2" + "revision" : "3312f9f50e3103e54c2c9b09b823f40a16e0c6cb", + "version" : "1.6.0" } } ], - "version" : 2 + "version" : 3 } diff --git a/ExampleApp/ExampleApp/AppDelegate.m b/ExampleApp/ExampleApp/AppDelegate.m index 2d048a6..9644d03 100644 --- a/ExampleApp/ExampleApp/AppDelegate.m +++ b/ExampleApp/ExampleApp/AppDelegate.m @@ -22,7 +22,10 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( // Mobile is not installed, pass an instance of IQUIOverrideDelegate to this // method(such as self in this example). You can then bypass the alert dialog // or provide your own. - [[ConnectIQ sharedInstance] initializeWithUrlScheme:ReturnURLScheme uiOverrideDelegate:nil]; + // Using URL Scheme + //[[ConnectIQ sharedInstance] initializeWithUrlScheme:ReturnURLScheme uiOverrideDelegate:nil]; + // Using Universal links + [[ConnectIQ sharedInstance] initializeWithUniversalLinks:ReturnURLHost uiOverrideDelegate:nil]; [[DeviceManager sharedManager] restoreDevicesFromFileSystem]; // Override point for customization after application launch. @@ -57,12 +60,21 @@ - (void)applicationWillTerminate:(UIApplication *)application { } - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(nonnull NSDictionary *)options { + // Handle Garmin Connect app attempting to launch this companion app using URL scheme NSString* sourceApp = options[UIApplicationOpenURLOptionsSourceApplicationKey]; NSLog(@"Received URL from '%@': %@", sourceApp, url); return [[DeviceManager sharedManager] handleOpenURL:url]; } +- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray> * _Nullable))restorationHandler { + // Handle Garmin Connect app attempting to launch this companion app using universal link + if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) { + return [[DeviceManager sharedManager] handleOpenURL:userActivity.webpageURL]; + } + return NO; +} + - (void)needsToInstallConnectMobile { // If you set self as the UI override delegate in the SDK's initialize method, // this method will be called if the SDK needs to install GCM. In this example, diff --git a/ExampleApp/ExampleApp/AppMessageViewController.m b/ExampleApp/ExampleApp/AppMessageViewController.m index e892d43..545686c 100644 --- a/ExampleApp/ExampleApp/AppMessageViewController.m +++ b/ExampleApp/ExampleApp/AppMessageViewController.m @@ -194,7 +194,7 @@ - (void)sendMessage:(id)message { LogMessage(@"%02.2f%% - %u/%u", percent, sentBytes, totalBytes); } completion:^(IQSendMessageResult result) { LogMessage(@"Send message finished with result %@", NSStringFromSendMessageResult(result)); - }]; + } isTransient:(false)]; } - (void)logMessage:(NSString *)message { diff --git a/ExampleApp/ExampleApp/Constants.h b/ExampleApp/ExampleApp/Constants.h index 388ce12..fba0225 100644 --- a/ExampleApp/ExampleApp/Constants.h +++ b/ExampleApp/ExampleApp/Constants.h @@ -8,3 +8,4 @@ #import extern NSString * const ReturnURLScheme; +extern NSString * const ReturnURLHost; diff --git a/ExampleApp/ExampleApp/Constants.m b/ExampleApp/ExampleApp/Constants.m index c281414..74a35f1 100644 --- a/ExampleApp/ExampleApp/Constants.m +++ b/ExampleApp/ExampleApp/Constants.m @@ -8,3 +8,4 @@ #import "Constants.h" NSString * const ReturnURLScheme = @"exapp-123456"; +NSString * const ReturnURLHost = @"connect.garmin.com/devices-list"; diff --git a/ExampleApp/ExampleApp/DeviceManager.m b/ExampleApp/ExampleApp/DeviceManager.m index 1a5eaae..c9d049a 100644 --- a/ExampleApp/ExampleApp/DeviceManager.m +++ b/ExampleApp/ExampleApp/DeviceManager.m @@ -61,7 +61,7 @@ - (instancetype)initPrivate { // -------------------------------------------------------------------------------- - (BOOL)handleOpenURL:(NSURL *)url { - if ([url.scheme isEqualToString:ReturnURLScheme]) { + if ([url.scheme isEqualToString:ReturnURLScheme] || [url.scheme isEqualToString:@"https"]) { NSArray *devices = [[ConnectIQ sharedInstance] parseDeviceSelectionResponseFromURL:url]; if (devices != nil) { NSLog(@"Forgetting %d known devices.", (int)self.devices.count); diff --git a/ExampleApp/ExampleApp/ExampleApp.entitlements b/ExampleApp/ExampleApp/ExampleApp.entitlements new file mode 100644 index 0000000..7f0f505 --- /dev/null +++ b/ExampleApp/ExampleApp/ExampleApp.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.developer.associated-domains + + applinks:connect.garmin.com + + +