Segmentation

Addressing Devices

To help target specific devices or users for a notification, we have Tags, Named Users and Tag Groups.

Tags

Tags are an easy way to group channels. Many tags can be applied to one or more devices. Then, a message sent to a tag will be sent out to all devices that are associated with that tag. After modifying tags, make sure to call updateRegistration to have the SDK sync the tags with Urban Airship.

Modifying tags
// Set tags
UAirship.push().tags = ["one", "two", "three"]

// Add a tag
UAirship.push().addTag("a_tag")

// Remove a tag
UAirship.push().removeTag("a_tag")

// Update registration
UAirship.push().updateRegistration()
// Setting tags
[UAirship push].tags = @[@"one", @"two", @"three"];

// Add a tag
[[UAirship push] addTag:@"a_tag"];

// Remove a tag
[[UAirship push] removeTag:@"a_tag"];

// Update registration
[[UAirship push] updateRegistration];

Named Users

Note

Associating the channel with a Named User ID will implicitly disassociate the channel from the previously associated Named User ID, if an association existed.

Named Users allow you to associate multiple devices to a single user or profile that may be associated with more than one device, e.g., an end-user's iPhone and iPad. A device can have only one Named User, and a single Named User should not be associated with more than 50 devices. Named Users provide the ability to directly set tags on them (see Tag Groups).

Setting the named user
UAirship.namedUser().identifier = "NamedUserID"
[UAirship namedUser].identifier = @"NamedUserID";

By default, Named Users can only be associated server-side. A 403 Forbidden response is returned if Named User association is attempted when client-side association is disabled. In order to associate a Named User through the application, you must change the application's Named User security setting to allow Named Users to be set from devices. Please visit the Settings documentation to enable this option.

Tag Groups

Note

If setting channel tags is enabled on the device, the predefined device Tag Group cannot be modified from the device and will log an error message. Disable channel tags by disabling channelTagRegistrationEnabled on the UAPush instance if you want to modify this "default" Tag Group.

Tag groups are configurable namespaces for organizing tags for the channel and Named User. Please view the Tag Groups documentation for more details. The Create and push to a tag group guides you through creating and using Tag Groups.

Channel Tag Group Example
// Add tags to a group
UAirship.push().addTags(["silver-member", "gold-member"], group:"loyalty")

// Remove tags from a group
UAirship.push().removeTags(["bronze-member", "club-member"], group:"loyalty")

// Set tags on a group
UAirship.push().setTags(["bingo"], group:"games")

// Update registration
UAirship.push().updateRegistration()
// Add tags to a group
[[UAirship push] addTags:@[@"silver-member", @"gold-member"] group:@"loyalty"];

// Remove tags from a group
[[UAirship push] removeTags:@[@"bronze-member", @"club-member"] group:@"loyalty"];

// Set tags on a group
[[UAirship push] setTags:@[@"bingo"] group:@"games"];

// Force a registration update
[[UAirship push] updateRegistration];
Named User Tag Group Example
// Add tags to a group
UAirship.namedUser().addTags(["silver-member", "gold-member"], group:"loyalty")

// Remove tags from a group
UAirship.namedUser().removeTags(["bronze-member", "club-member"], group:"loyalty")

// Set tags on a group
UAirship.namedUser().setTags(["bingo"], group:"games")

// Force a registration update
UAirship.namedUser().updateTags()
// Add tags to a group
[[UAirship namedUser] addTags:@[@"silver-member", @"gold-member"] group:@"loyalty"];

// Remove tags from a group
[[UAirship namedUser] removeTags:@[@"bronze-member", @"club-member"] group:@"loyalty"];

// Set tags on a group
[[UAirship namedUser] setTags:@[@"bingo"] group:@"games"];

// Force a registration update
[[UAirship namedUser] updateTags];

By default, Tag Groups can only be modified from the server. A 403 Forbidden response is returned if Tag Groups modification is attempted when client-side Tag Groups is disabled. In order to modify Tag Groups through the application, you must change the application's Tag Group security settings to allow these tags to be set from devices. Please visit the Settings documentation to enable this option.

Urban Airship Channel IDs

The Channel ID is a unique identifier that ties together an application/device pair on iOS devices. The Channel ID is used to target pushes to specific devices using the Urban Airship API.

The Channel ID will be logged for all apps. You can get the channelID with a couple of extra lines to your application:

Channel ID Access
let channelID = UAirship.push().channelID
print("My Application Channel ID: \(channelID)")
NSString *channelID = [UAirship push].channelID;
NSLog(@"My Application Channel ID: %@", channelID);

Don't worry if this value initially comes back as null on your app's first run as the Channel ID will be created and persisted during registration.

You can listen for channel creation by either adding an NSNotificationCenter observer for UAChannelCreatedEvent or by implementing the UARegistrationDelegate protocol and setting the registration delegate on UAPush . You can listen for channel updates by adding an NSNotificationCenter observer for UAChannelUpdatedEvent .

Adding an NSNotificationCenter observer for UAChannelCreatedEvent
NotificationCenter.default.addObserver(self,
                              selector:#selector(myClass.mySelector),
                                  name:NSNotification.Name(UAChannelCreatedEvent),
                                object:nil);
// Add observer to the UAChannelCreatedEvent
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(mySelector)
                                             name:UAChannelCreatedEvent object:nil];
Implementing the UARegistrationDelegate protocol
func registrationSucceeded(forChannelID channelID: String, deviceToken: String) {
    // Registration succeeded
}
- (void)registrationSucceededForChannelID:(NSString *)channelID deviceToken:(nonnull NSString *)deviceToken {
    // Registration succeeded
}
Setting the registration delegate on UAPush
UAirship.push().registrationDelegate = self
[UAirship push].registrationDelegate = self;