iOS Initialization
Here you will learn how to set up all the Group Link iOS SDK functions to run properly in your application.
Step 1 - Initialize the Group Link SDK
Start the library
To initialize the library, a Group Link Token is needed. On your AppDelegate implementation, import the library, and, in the didFinishLaunchingWithOptions:
App Delegate (Obj-C) - Implementation
1#import "AppDelegate.h"2@import GroupLink;34@interface AppDelegate ()56@end78@implementation AppDelegate910- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {11 // Override point for customization after application launch.12 [GroupLinkSDK startWithToken: @"GROUP_LINK_TOKEN"];1314 return YES;15}
App Delegate - Implementation
1import UIKit2import GroupLink34@UIApplicationMain5class AppDelegate: UIResponder, UIApplicationDelegate {67 func application(_ application: UIApplication,8 didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {9 GroupLinkSDK.start(token: "GROUP_LINK_TOKEN")1011 ...1213 return true14 }15}
SwiftUI App Cycle - Implementation (iOS 14)
1import SwiftUI2import GroupLink34@main5struct SwiftUIApp: App {6 init() {7 GroupLinkSDK.start(token: "GROUP_LINK_TOKEN")8 }910 ..1112 var body: some Scene {13 WindowGroup {14 ContentView()15 }16 }17}
Step 2 - Request User Bluetooth Authorization
Anywhere in your App, request authorization to use the user's Bluetooth. If you don't have a Bluetooth manager stack, you just need to call the Group Link framework Bluetooth function, which will request the user authorization to use Bluetooth services. We recommend that you call this function at the start of your application. If you ask for permission after some screen like a login screen, our SDK may not start.
App Delegate (Obj-C) - Implementation
1#import "AppDelegate.h"2@import GroupLink;34@interface AppDelegate ()56@end78@implementation AppDelegate910- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {11 // The permission is required to start the SDK's Bluetooth manager.12 // You can execute it during your app's initialization.13 [GroupLinkSDK startBluetooth];1415 return YES;16}
App Delegate - Implementation
1import UIKit2import GroupLink34@UIApplicationMain5class AppDelegate: UIResponder, UIApplicationDelegate {67 func application(_ application: UIApplication,8 didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {9 // The permission is required to start the SDK's Bluetooth manager.10 // You can execute it during your app's initialization.11 GroupLinkSDK.startBluetooth()1213 ...1415 return true16 }17}
SwiftUI App Cycle - Implementation (iOS 14)
1import SwiftUI2import GroupLink34@main5struct SwiftUI_TestApp: App {6 init() {7 // The permission is required to start the SDK's Bluetooth manager.8 // You can execute it during your app's initialization.9 GroupLinkSDK.startBluetooth()10 }1112 ...13}
If you are already using the CoreBluetooth framework, call this method within the .poweredOn state of your Bluetooth delegate:
1- (void)centralManagerDidUpdateState:(CBCentralManager *)central {2 switch ([central state])3 {4 case CBCentralManagerStatePoweredOn:5 [GroupLinkSDK startBluetooth];6 break;7 default:8 break;9 }10}
1func centralManagerDidUpdateState(_ central: CBCentralManager) {2 switch central.state {3 case .poweredOn:4 GroupLinkSDK.startBluetooth()5 default:6 break7 }8}
Remember to always check if the user has granted Bluetooth permission when initializing your application, with the checkBluetooth() SDK function.
App Delegate (Obj-C) - Implementation
1#import "AppDelegate.h"2@import GroupLink;34@interface AppDelegate ()56@end78@implementation AppDelegate910- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {11 // It is recommended to run this function to check if the user has granted Bluetooth permission.12 // This function will not prompt for anything. You must call the startBluetooth() function to request permission.13 [GroupLinkSDK checkBluetooth];1415 return YES;16}
App Delegate - Implementation
1import UIKit2import GroupLink34@UIApplicationMain5class AppDelegate: UIResponder, UIApplicationDelegate {67 func application(_ application: UIApplication,8 didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {9 // It is recommended to run this function to check if the user has granted Bluetooth permission.10 // This function will not prompt for anything. You must call the startBluetooth() function to request permission.1112 GroupLinkSDK.checkBluetooth()1314 ...1516 return true17 }18}
SwiftUI App Cycle - Implementation (iOS 14)
1import SwiftUI2import GroupLink34@main5struct SwiftUI_TestApp: App {6 init() {7 // It is recommended to run this function to check if the user has granted Bluetooth permission.8 // This function will not prompt for anything. You must call the startBluetooth() function to request permission.9 GroupLinkSDK.checkBluetooth()10 }1112 ...13}
Step 3 - Request User Location Authorization
Anywhere in your App, request authorization to use the user's location. If you don't have a location manager stack, you just need to call the Group Link framework location function, which will request the user authorization to use location services. We recommend that you call this function at the start of your application. If you ask for permission after some screen like a login screen, our SDK may not start.
App Delegate (Obj-C) - Implementation
1#import "AppDelegate.h"2@import GroupLink;34@interface AppDelegate ()56@end78@implementation AppDelegate910- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {11 // The permission is required to start the SDK's location manager.12 // You can execute it during your app's initialization.13 [GroupLinkSDK startLocation];1415 return YES;16}
App Delegate - Implementation
1import UIKit2import GroupLink34@UIApplicationMain5class AppDelegate: UIResponder, UIApplicationDelegate {67 func application(_ application: UIApplication,8 didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {9 // The permission is required to start the SDK's location manager.10 // You can execute it during your app's initialization.11 GroupLinkSDK.startLocation()1213 ...1415 return true16 }17}
SwiftUI - Implementation (iOS 14)
1import SwiftUI2import GroupLink34@main5struct SwiftUI_TestApp: App {6 init() {7 // The permission is required to start the SDK's location manager.8 // You can execute it during your app's initialization.9 GroupLinkSDK.startLocation()10 }111213 ...14}
Group Link will now start monitoring sensors in range.