Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delay push notifications permission popup Swift

Tags:

ios

swift

iphone

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

like image 468
Rawan Avatar asked Nov 02 '25 00:11

Rawan


1 Answers

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

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()
        }
    }
like image 80
Bhargav Narkedamilli Avatar answered Nov 03 '25 15:11

Bhargav Narkedamilli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!