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[[PushIOManagersharedInstance]registerCategory:@"US"];}else{// Unregister for US Headlines[[PushIOManagersharedInstance]unregisterCategory:@"US"];}}
// Register a categoryPushIOManager.sharedInstance().registerCategory("Category")// Register a list of categoriesletcategories=["Category1","Category2"]PushIOManager.sharedInstance().registerCategories(categories)// Unregister a categoryPushIOManager.sharedInstance().unregisterCategory("Category1")//Unregister a list of categoriesletcategories=["Category1","Category2"]PushIOManager.sharedInstance().unregisterCategories(categories)//Unregister all categoriesPushIOManager.sharedInstance().unregisterAllCategories()
This kind of registration can be tied to a UI Action, such as a UI Switch:
You can also ask PushIOManager if a category is registered, to help configure your UI:
-(void)viewWillAppear{[superviewWillAppear];// Set UI switches based upon Push IO registration status_usSwitch.on=[[PushIOManagersharedInstance]isRegisteredForCategory:@"US"];_sportsSwitch.on=[[PushIOManagersharedInstance]isRegisteredForCategory:@"Sports"];}
// Check for a CategoryletisCatRegistered=PushIOManager.sharedInstance().isRegistered(forCategory:"Category1")// Retrieve CategoriesletregdCategories=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:
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;[[PushIOManagersharedInstance]configureWithAPIKey:API_KEYaccountToken:ACCOUNT_TOKENerror:&error];if(nil==error){NSLog(@"SDK Configured Successfully");}else{NSLog(@"Unable to configure SDK, reason: %@",error.description);}
varapiKey:StringvaraccountToken:String//FIXME: correct the apiKey and accountToken values#ifDEBUGapiKey="DEBUG_APIKEY";//Copy the apiKey value from pushio_config_debug.jsonaccountToken="DEBUG_ACCOUNT_TOKEN";//Copy the accountToken value from pushio_config_debug.json. Assign nil if no value available.#elseapiKey="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.#endifdo{tryPushIOManager.sharedInstance().configure(withAPIKey:apiKey,accountToken:accountToken)}catch{print("Unable to configure, reason:\(error)")}
[2.] Once the SDK is configured successfully, register as follows:
[[PushIOManagersharedInstance]registerForAllRemoteNotificationTypes:^(NSError*error,NSString*deviceToken){if(nil==error){NSError*regTrackError=nil;[[PushIOManagersharedInstance]registerApp:®TrackErrorcompletionHandler:^(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 ApplePushIOManager.sharedInstance().register(forAllRemoteNotificationTypes:{(regTrackError,deviceToken)inif(regTrackError==nil){print("Device Token: \(deviceToken)")do{// Register application with SDK.tryPushIOManager.sharedInstance().registerApp(completionHandler:{(regError,response)inif(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: