jbo*_*ono 3 ios firebase swift firebase-notifications
我正在使用Firebase通知的应用程序.我在AppDelegate中配置了它,它们运行良好.
问题:我有一个带开关的设置视图,打开/关闭通知,我不知道如何禁用通知.我试过这个,但是没有用:
@IBAction func changeSwitch(_ sender: Any) {
if mySwitch.isOn {
print("NOTIFICATIONS ON")
connectToFcm()
} else {
print("NOTIFICATIONS OFF")
FIRMessaging.messaging().disconnect()
}
}
func connectToFcm() {
FIRMessaging.messaging().connect { (error) in
if (error != nil) {
print("Unable to connect with FCM. \(error)")
} else {
print("Connected to FCM.")
}
}
}
Run Code Online (Sandbox Code Playgroud)
也许你可以帮助我.
谢谢!
可以从设备本身禁用/启用通知,如下所示:
func switchChanged(sender: UISwitch!) {
print("Switch value is \(sender.isOn)")
if(sender.isOn){
UIApplication.shared.registerForRemoteNotifications()
}
else{
UIApplication.shared.unregisterForRemoteNotifications()
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1578 次 |
| 最近记录: |