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.
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.