Change push notifications programmatically in Swift

前端 未结 4 2076
天涯浪人
天涯浪人 2021-01-05 16:08

I have an app where I have implemented push notifications. I check with the user to allow remote notifications with:

let settings = UIUserNotificationSetting         


        
4条回答
  •  一整个雨季
    2021-01-05 16:55

    Updated with swift 4 :

    func switchChanged(sender: UISwitch!) {
        print("Switch value is \(sender.isOn)")
    
        if(sender.isOn){
            print("on")
            UIApplication.shared.registerForRemoteNotifications()
        }
        else{
            print("Off")
            UIApplication.shared.unregisterForRemoteNotifications()
        }
    }
    

提交回复
热议问题