ios – 按下按钮后如何提示用户提供推送通知权限?

ios – 按下按钮后如何提示用户提供推送通知权限?,第1张

概述我读了 How to control when to prompt user for push notification permissions in iOS和类似的问题,但它们不是用Swift 3编写的. 我已经读了五次Registering for Push Notifications in Xcode 8/Swift 3.0?. 我一遍又一遍地在模拟器中运行我的应用程序但是在第一次之后,应用 我读了 How to control when to prompt user for push notification permissions in iOS和类似的问题,但它们不是用Swift 3编写的.

我已经读了五次Registering for Push Notifications in Xcode 8/Swift 3.0?.

我一遍又一遍地在模拟器中运行我的应用程序但是在第一次之后,应用程序从未提示用户提供推送通知权限.

我使用了Registering for Push Notifications in Xcode 8/Swift 3.0?中的代码并继续尝试不同的答案并将代码移动到不同的位置,这样只有在按下某个按钮后才会要求用户许可,而不是在应用程序启动时立即.

我是否必须使用Apple ID等注册推送通知代码才能在Simulator中工作?

解决方法 首先,您应该只提示您的用户是否想要获得推送通知.因此,将其绑定到按钮并尝试每次都运行它是一个糟糕的用户体验决定.如果按钮实际上执行了更多需要启用推送通知的内容,则只将推送通知提示绑定到按钮.

要注册用户以进行推送通知,您应该使用UIApplication registerForRemoteNotifications方法.运行此方法时,系统会提示用户是否要接收推送通知 – 但只提示一次!他们设置的设置将被视为确定,并且不会再次提示您的用户.如果他们想要开始接收推送通知,他们必须在应用程序的设置中更改它.这是预期的行为,你应该怎么做.

如果您只想在按下按钮时提示用户,则从应用程序的启动代码中删除对registerForRemoteNotifications的任何调用,并从绑定到按钮的 *** 作中调用该方法.

如果要重置推送通知权限以进行测试,请参见this is how Apple says it’s possible:

resetting the Push Notifications Permissions Alert on 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.

If you want to simulate a first-time run of your app,you can leave the app uninstalled for a day. You can achIEve the latter without actually waiting a day by following these steps:

Delete your app from the device. Turn the device off completely and turn it back on. Go to Settings > General > Date & Time and set the date ahead a day or more. Turn the device off completely again and turn it back on.
总结

以上是内存溢出为你收集整理的ios – 按下按钮后如何提示用户提供推送通知权限?全部内容,希望文章能够帮你解决ios – 按下按钮后如何提示用户提供推送通知权限?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1055645.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存