SDK

Tags

In this page you'll learn more about device segmentation. With tags you can categorize devices through your app. Tags can assume as many forms as you want and a device can have an unlimited number of tags. This will be extremely useful if your app doesn't have any means of authentication and your audience is mainly composed by anonymous devices.

Common use cases for tags involve creating categories that separated devices by device model, capabilities or properties, like tablet, hasCam or en-GB. You might also allow users to subscribe to a list of pre-defined tags you include in your app. Many use cases for tags, allow users to subscribed to categories like wants_news_for_music or subscribed_newslleter. You can also register tags upon events in your app, like bought_shoes or was_near_beacon_x.

Tags are only available after a device has been successfully registered in Notificare so the best place to access, add or remove them is after device registration. Add the following to retrieve the list of tags assigned to this device:

-(void)notificarePushLib:(NotificarePushLib *)library didRegisterDevice:(NotificareDevice *)device {

    [[NotificarePushLib shared] fetchTags:^(id  _Nullable response, NSError * _Nullable error) {
        if (!error) {
            //Response will be a NSArray of strings
        }
    }];

}
func notificarePushLib(_ library: NotificarePushLib, didRegister device: NotificareDevice) {
    NotificarePushLib.shared().fetchTags({(_ response: Any?, _ error: Error?) -> Void in
        if error == nil {
            //Response will be a NSArray of strings
        }
    })
}

To assign a tag to a device, invoke the method below:

[[NotificarePushLib shared] addTag:@"tag_press" completionHandler:^(id  _Nullable response, NSError * _Nullable error) {
    if (!error) {
        //Tag added
    }
}];
NotificarePushLib.shared().addTag("tag_press", completionHandler: {(_ response: Any?, _ error: Error?) -> Void in
    if error == nil {
        //Tag added
    }
})

To assign more than one tag to a device at once, invoke the method below:

[[NotificarePushLib shared] addTags:@[@"tag_press", @"tag_news"] completionHandler:^(id  _Nullable response, NSError * _Nullable error) {
    if (!error) {
        //Tags added
    }
}];
NotificarePushLib.shared().addTags(["tag_press", "tag_news"], completionHandler: {(_ response: Any?, _ error: Error?) -> Void in
    if error == nil {
        //Tags added
    }
})

Or remove a specific tag from a device:

[[NotificarePushLib shared] removeTag:@"tag_press" completionHandler:^(id  _Nullable response, NSError * _Nullable error) {
    if (!error) {
        //Tag removed
    }
}];
NotificarePushLib.shared().removeTag("tag_press", completionHandler: {(_ response: Any?, _ error: Error?) -> Void in
    if error == nil {
        //Tag removed
    }
})

To remove more than one tag from a device at once:

[[NotificarePushLib shared] removeTags:@[@"tag_press", @"tag_news"] completionHandler:^(id  _Nullable response, NSError * _Nullable error) {
    if (!error) {
        //Tags removed
    }
}];
NotificarePushLib.shared().removeTags(["tag_press", "tag_news"], completionHandler: {(_ response: Any?, _ error: Error?) -> Void in
    if error == nil {
        //Tags removed
    }
})

Finally you can also remove all the tags from a device:

[[NotificarePushLib shared] clearTags:^(id  _Nullable response, NSError * _Nullable error) {
    if (!error) {
        //Tags cleared
    }
}];
NotificarePushLib.shared().clearTags({(_ response: Any?, _ error: Error?) -> Void in
    if error == nil {
        //Tags cleared
    }
})

You have now implemented successfully device tags and can start sending push notifications based on these categories.