在Swift中以编程方式更改推送通知 [英] Change push notifications programmatically in Swift

查看:92
本文介绍了在Swift中以编程方式更改推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我已经实现了推送通知。我检查用户是否允许远程通知:

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

let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
UIApplication.sharedApplication().registerForRemoteNotifications()

我还将响应存储在带有设备令牌的数据库中。

I also store the response in a DB with the device token.

我还在设置中实现了UISwitch页面启用/禁用推送通知但是我只能在数据库列中启用/禁用此功能。

I have also implemented a UISwitch in a settings page to enable/disable push notifications however I have only been able to enable/disable this in the DB column.

我的问题是如果用户选择了不允许在初始请求中,我无法在手机设置中启用推送通知,因此即使我在数据库中将值设置为启用,通知仍将无法到达手机,因为手机设置仍设置为禁用。

My problem is that if a user selected Don't Allow in the initial request, I cannot enable push notifications in the phone settings so even if I set the value to enable in the DB, the notification will never reach the phone as the phone settings are still set to disable.

Swift 2中是否有办法从wi更改手机设置中的推送通知瘦应用程序而不是用户必须进入设置更改?或者让UISwitch允许用户切换开/关推送通知是完全多余的?

Is there a way in Swift 2 to change the push notification in the phone setting from within the app instead of the user having to go in to the settings to change? Or is it completely redundant to have a UISwitch allow the user to toggle on/off push notifications?

推荐答案

没有任何您可以从程序更改推送通知权限状态的方式。此外,无法一次又一次地显示要求用户允许推送通知的提示。您可以参考此 https://developer.apple.com/library/ios /technotes/tn2265/_index.html

There isn't any way you can change push notifications permission status from program. Also, prompt asking user to allow push notifications can not be shown again and again. You can refer this https://developer.apple.com/library/ios/technotes/tn2265/_index.html.


第一次启用推送的应用注册推送通知时,iOS要求用户是否希望接收该应用的通知。一旦用户响应此警报,除非设备已恢复或应用程序已卸载至少一天,否则不会再次显示该警报。

The first time a push-enabled app registers for push notifications, iOS asks the user if they wish to receive notifications for that app. Once the user has responded to this alert it is not presented again unless the device is restored or the app has been uninstalled for at least a day.

因此,除非您使用开关状态打开/关闭服务器的远程通知,否则使用UISwitch切换权限状态没有任何意义。

So using UISwitch to toggle permission status doesn't make any sense unless you use switch status to turn on/off remote notifications from your server.

这篇关于在Swift中以编程方式更改推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆