如何延迟推送通知权限弹出Swift

编程入门 行业动态 更新时间:2024-10-27 19:24:26
本文介绍了如何延迟推送通知权限弹出Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在开发一个带推送通知的应用,我希望延迟推送通知权限的出现,直到用户第三次进入我的应用程序。所以他应该对我的应用感兴趣,然后我想问他的许可。 我有办法做到这一点吗? 我搜索了很多方法,比如这里: 重置推送应用的通知设置 但我没有得到任何有用的答案。 请帮助。 谢谢

I'm working on an app with push notifications, I want to delay the appearance of the push notifications permission pop up until after the user enters my app for the third time. So he should be interested in my app, then I want to ask him for his permission. I there a way to do that? I searched a lot for a way, like here: Reset push notification settings for app but I didn't get any useful answers. Please Help. Thanks

推荐答案

维护一个在中递增的userDefault - (BOOL)应用程序:(UIApplication * )application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {}method

Maintain one userDefault which increments in "- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {}" method

如果userDefault大于3,则寻求Notification的许可

if the userDefault is greater than 3,then seek for permission of Notification

if NSUserDefaults.standardUserDefaults().objectForKey("launchCount")?.integerValue >= 3{ if UIApplication.sharedApplication().respondsToSelector("isRegisteredForRemoteNotifications") { UIApplication.sharedApplication().registerUserNotificationSettings( UIUserNotificationSettings( forTypes: [.Alert, .Badge, .Sound], categories: nil)) UIApplication.sharedApplication().registerForRemoteNotifications() } }

更多推荐

如何延迟推送通知权限弹出Swift

本文发布于:2023-10-06 19:47:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1467645.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:弹出   权限   通知   Swift

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!