如何延迟推送通知权限弹出Swift [英] How to delay push notifications permission popup Swift

查看:312
本文介绍了如何延迟推送通知权限弹出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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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