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_shoesor 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:

...more code

[[NotificarePushLib shared] registerDevice:deviceToken completionHandler:^(NSDictionary *info) {

    ...more code

    [[NotificarePushLib shared] getTags:^(NSDictionary *info) {

        //Handle success

    } errorHandler:^(NSError *error) {

        //Handle error
    }];

} errorHandler:^(NSError *error) {
    //Handle error
}];

...more code
... more code

NotificarePushLib.shared().registerDevice(deviceToken, completionHandler: {(_ info: [AnyHashable: Any]) -> Void in

    ... more code

    NotificarePushLib.shared().getTags({(_ info: [AnyHashable: Any]) -> Void in

        //Handle success

    }, errorHandler: {(_ error: Error?) -> Void in

        //Handle error
    })

    ...more code
}, errorHandler: {(_ error: Error?) -> Void in

    Handle error

})

... more code

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

[[NotificarePushLib shared] addTags:@[@"onetag",@"twotags"] completionHandler:^(NSDictionary *info) {

    //Handle success

} errorHandler:^(NSError *error) {

    //Handle error
}];
NotificarePushLib.shared().addTags(["onetag", "twotags"], completionHandler: {(_ info: [AnyHashable: Any]) -> Void in

    //Handle success

}, errorHandler: {(_ error: Error?) -> Void in

    //Handle error

})

Or remove a specific tag from a device:

[[NotificarePushLib shared] removeTag:@"tag" completionHandler:^(NSDictionary *info) {

    //Handle success

} errorHandler:^(NSError *error) {

    //Handle error
}];
NotificarePushLib.shared().removeTag("tag", completionHandler: {(_ info: [AnyHashable: Any]) -> Void in
    //Handle success
}, errorHandler: {(_ error: Error?) -> Void in
    //Handle error
})

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

[[NotificarePushLib shared] clearTags:^(NSDictionary *info) {

    //Handle success

} errorHandler:^(NSError *error) {

    //Handle error
}];
NotificarePushLib.shared().clearTags({(_ info: [AnyHashable: Any]) -> Void in

    //Handle success

}, errorHandler: {(_ error: Error?) -> Void in

    //Handle error

})

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