Oracle Help Center | Oracle Push Cloud Service (Standalone) title

Implementing Categories

If your application provides users a way to specify a preference or favorite, you may want to register devices for categories so you can push relevant content to your users:

- (IBAction)switchAction:(id)sender
{
     UISwitch *mySwitch = (UISwitch *)sender;

     if (mySwitch.on == YES)
     {
        // Register for US Headlines
        [[PushIOManager sharedInstance] registerCategory:@"US"];
     }
     else
     {
        // Unregister for US Headlines
        [[PushIOManager sharedInstance] unregisterCategory:@"US"];
     }
}
        
// Register a category
PushIOManager.sharedInstance().registerCategory("Category")

// Register a list of categories
let categories = ["Category1", "Category2"]
PushIOManager.sharedInstance().registerCategories(categories)


// Unregister a category
PushIOManager.sharedInstance().unregisterCategory("Category1")

//Unregister a list of categories
let categories = ["Category1", "Category2"]
PushIOManager.sharedInstance().unregisterCategories(categories)

//Unregister all categories
PushIOManager.sharedInstance().unregisterAllCategories()
        

This kind of registration can be tied to a UI Action, such as a UI Switch:

"Example of a UI switch for turning on categories"

You can also ask PushIOManager if a category is registered, to help configure your UI:

- (void)viewWillAppear
{
    [super viewWillAppear];

    // Set UI switches based upon Push IO registration status
    _usSwitch.on = [[PushIOManager sharedInstance] isRegisteredForCategory:@"US"];
    _sportsSwitch.on = [[PushIOManager sharedInstance] isRegisteredForCategory:@"Sports"];
}
        
// Check for a Category
let isCatRegistered = PushIOManager.sharedInstance().isRegistered(forCategory: "Category1")

// Retrieve Categories
let regdCategories = PushIOManager.sharedInstance().allRegisteredCategories()
        

Tip: There's a great way to check if your registration code is working. If you log into the Web Dashboard --> Set Up --> Categories section, you will see each category and its total number of registered devices:

"PushIO Web Dashboard, Set Up tab, Categories section"

Also, by default, the PushIOManager registers each user for a broadcast category, so that you can push to all your users. Users can be registered for the broadcast push category as follows:

[1.] Ensure that your application implements Configure SDK with a valid APIKey and accountToken (Pass nil for accountToken if it's not applicable):

NSError *error = nil;

    [[PushIOManager sharedInstance] configureWithAPIKey:API_KEY accountToken:ACCOUNT_TOKEN error:&error];
    if(nil == error){
        NSLog(@"SDK Configured Successfully");
    }else{
        NSLog(@"Unable to configure SDK, reason: %@", error.description);
    }
        
var apiKey : String
var accountToken : String
//FIXME: correct the apiKey and accountToken values
#if DEBUG
    apiKey = "DEBUG_APIKEY";//Copy the apiKey value from pushio_config_debug.json
    accountToken = "DEBUG_ACCOUNT_TOKEN";//Copy the accountToken value from pushio_config_debug.json. Assign nil if no value available.
#else
    apiKey = "RELEASE_APIKEY";//Copy the apiKey value from pushio_config.json.
    accountToken = "RELEASE_ACCOUNT_TOKEN";//Copy the accountToken value from pushio_config.json. Assign nil if no value available.
#endif
 
do{
    try PushIOManager.sharedInstance().configure(withAPIKey: apiKey, accountToken: accountToken)
}catch{
    print("Unable to configure, reason:\(error)")
}
        

[2.] Once the SDK is configured successfully, register as follows:

[[PushIOManager sharedInstance] registerForAllRemoteNotificationTypes:^(NSError *error, NSString *deviceToken) {
    if (nil == error) {
        NSError *regTrackError = nil;
        [[PushIOManager sharedInstance] registerApp:&regTrackError completionHandler:^(NSError *regAppError, NSString *response) {
            if (nil == regAppError) {
                NSLog(@"Application registered successfully!");
            }else{
                NSLog(@"Unable to register application, reason: %@", regAppError.description);
            }
        }];
        if (nil == regTrackError) {
            NSLog(@"Registration locally stored successfully.");
        }else{
            NSLog(@"Unable to store registration, reason: %@", regTrackError.description);
        }
    }
}];
        
// Requests a device token from Apple
PushIOManager.sharedInstance().register(forAllRemoteNotificationTypes: { (regTrackError, deviceToken) in
    if (regTrackError == nil) {
        print("Device Token: \(deviceToken)")
        do{
            // Register application with SDK.
            try PushIOManager.sharedInstance().registerApp(completionHandler: { (regError, response) in
                if (regError == nil) {
                    print("Registration successful")
                }
                else {
                    print("Unable to register, reason: \(regError)")
                }
            })
        }catch{
            print("Error occurred while performing register, reason: \(error)")
        }
    }
})
        

To unregister users from the broadcast push category, you must unregister them from the app:

NSError *unregError = nil;
BOOL unregistered = [manager unregisterApp:&unregError completionHandler:^(NSError *error, NSString *response) {
    if (nil == error) {
        NSLog(@"Unregister successful.");
    }else{
        NSLog(@"Failed to unregister, reason: %@", error.localizedDescription);
    }
}];
if (!unregistered) {
    NSLog(@"Error occurred while performing unregister, reason: %@", unregError.localizedDescription);
}
        
let unregError: Error? = nil
try? PushIOManager.sharedInstance().unregisterApp(completionHandler: {(_ error: Error?, _ response: String?) -> Void in
    if nil == error {
        print("Unregister Successful.")
    }
    else {
        print("Failed to unregister, reason: \(error!.localizedDescription)")
    }
})
if nil != unregError {
    print("Error occurred while performing unregister, reason: \(unregError!.localizedDescription)")
}