Device-server communication

The SDK has a bi-directional communication model with the server. This enables the SDK to run on a variable frequency model, which balances the fine trade-off between low latency tracking and battery efficiency, and improve robustness. For this purpose, the iOS SDK uses APNs silent remote notifications. This guide will take you through the APNs setup for the SDK.

[info] Prerequisites

This guide assumes you have configured APNs in your application. If you haven't, read the iOS documentation on APNs.

Configure APNs on the dashboard

APNs certs Log into the HyperTrack dashboard, and open your account settings. Upload your APNs development and distribution certificates (.pem files).

These certificates will only be used to send remote push notifications to your apps.

Enable remote notifications in the app

Background modes In the app capabilities, ensure that remote notifications inside background modes is enabled.

Registering and receiving notifications

The following changes inside AppDelegate will register the SDK for push notifications and route HyperTrack notifications to the SDK.

Register for notifications

Inside didFinishLaunchingWithOptions, use the SDK method to register for notifications.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
    ...
    HyperTrack.registerForNotifications()
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [HyperTrack registerForNotifications];
    return YES;
}

Register device token

Inside and didRegisterForRemoteNotificationsWithDeviceToken and didFailToRegisterForRemoteNotificationsWithError methods, add the relevant lines so that HyperTrack can register the device token.

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    ...
    HyperTrack.didRegisterForRemoteNotificationsWithDeviceToken(deviceToken: deviceToken)
}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
    ...
    HyperTrack.didFailToRegisterForRemoteNotificationsWithError(error: error)
}
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(nonnull NSData *)deviceToken{
    ...
    [HyperTrack didRegisterForRemoteNotificationsWithDeviceTokenWithDeviceToken:deviceToken];
}

-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(nonnull NSError *)error{
    ...
    [HyperTrack didFailToRegisterForRemoteNotificationsWithErrorWithError:error];
}

Receive notifications

Inside the didReceiveRemoteNotification method, add the HyperTrack receiver. This method parses only the notifications that sent from HyperTrack.

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
    if (HyperTrack.isHyperTrackNotification(userInfo: userInfo)){
        HyperTrack.didReceiveRemoteNotification(userInfo: userInfo)
    }

    // Do any additional handling for your app's notifications.
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
    if ([HyperTrack isHyperTrackNotificationWithUserInfo:userInfo]){
        [HyperTrack didReceiveRemoteNotificationWithUserInfo:userInfo];
    }

    // Do any additional handling for your application's notifications.
}

results matching ""

    No results matching ""