Steps

Note:

  • Code will be in swift 3 and Objective c

  • Add UISwitch to your Settings ViewController

Hook up your switch to your ViewController class file

Add those lines to your Actions

In your UIButton/UISwitch Actions add the following.

Swift :

 @IBAction func sampleSwitchValueChanged(_ sender: Any) {

    if sampleSwitch.isOn {
    print("ON")
    //Enable push notifications
    Pushbots.sharedInstance().toggleNotifications(true);
   }
else {
    print ("OFF")
    //Disable push notification
    Pushbots.sharedInstance().toggleNotifications(false);

  }
}

Objective C :

 - (IBAction)aPNSwitch:(UISwitch *)sender {

   if (sender.isOn) {

    //Enable push notifications
   [self.PushbotsClient toggleNotifications:true];

      }else{
        //Disable push notifications
        [self.PushbotsClient toggleNotifications:false];
    }
  }

It is so easy, Right ?

Note: You can find more information:

Did this answer your question?