Notifications

Notifications via Push Teliver sdk provides you the way to notify your customers about the events that can occur within the Operator and Consumer. Let’s see that in detail. You can know how to setup FCM in your iOS Project here.

  • Identifying Users

To send/recieve a notification to users, the device must be first identified to do so use the following method.

// Called when APNs has assigned the device a unique token
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        // Convert token to string
        let deviceTokenString = deviceToken.reduce(“”, {$0 + String(format: “%02X”, $1)})
        Teliver.identifyUser(forUser: "Consumer_1", withToken: deviceTokenString)
}
// Called when APNs has assigned the device a unique token
-(void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
    [Teliver identifyUserForUser:@"Consumer_1" withToken:deviceToken];
}

Note: Consumer_1 here can be your user’s unique identifier in your system for identification, this will reflect under Users on dashboard. Also you can use the method available without device token.

Ref: The above view will appear on dashboard on identifying user.


  • Handling push

To handle push notification follow the steps below.

// Push notification received
func application(_ application: UIApplication, didReceiveRemoteNotification data: [AnyHashable : Any]) {
        if(Teliver.isTeliverPush(data: data)){
        var aps = data["aps"] as! [String: AnyObject]
        var title = aps["alert"] as? String
        var messageJson = data["message"] as? String
        // Above messageJson has your message, command & tracking_id in Json.
        // Commands are of two types:
        // teliver_start_trip -> This command will be issued when a trip has been started.
        // teliver_event_push -> This Command will be issued when a custom event push is triggered.
        }else {
            //The push is not for us, You can handle it.
        }
}
-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)data{
    if([Teliver isTeliverPushWithData:data]) {
        NSString *messageJson = data[@"message"];
        // Above messageJson has your message, command & tracking_id in Json.
        // Commands are of two types:
        // teliver_start_trip -> This command will be issued when a trip has been started.
        // teliver_event_push -> This Command will be issued when a custom event push is triggered.
    }else {
        //The push is not for us, You can handle it.
    }
}

Note: Don’t forget to identify Consumer to receive push.

results matching ""

    No results matching ""