2

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

Community
  • 1
  • 1
Rawan
  • 1,589
  • 4
  • 23
  • 47

2 Answers2

3

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()
        }
    }
  • thanks, but how to "seek for permission of Notification" ? what is the suitable command should call it ? – Rawan Feb 02 '16 at 10:14
  • You can call this method when satisfying a condition if UIApplication.sharedApplication().respondsToSelector("isRegisteredForRemoteNotifications") { UIApplication.sharedApplication().registerUserNotificationSettings( UIUserNotificationSettings( forTypes: [.Alert, .Badge, .Sound], categories: nil)) UIApplication.sharedApplication().registerForRemoteNotifications() } – Bhargav Narkedamilli Feb 02 '16 at 10:38
  • this wont help either, you can not delay notification pop up. – Vijay Sanghavi Feb 02 '16 at 10:40
  • keep this code in condition, when your condition satisfies , Like it launched three times then call this method – Bhargav Narkedamilli Feb 02 '16 at 10:43
  • Good Answer. Had to look here for explanation for how to save launchCount to NSUserDefaults: http://stackoverflow.com/a/31966920/2628223 – BigRon Feb 25 '16 at 23:49
  • Is it working when background remote notifications enabled ? As I moved push prompt code to a different view controller but still its asking at the launch . Please let me know how to delay push prompt ?? – user1828845 Apr 07 '21 at 10:32
0

Use UIApplication's registerForRemoteNotifications method. https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/#//apple_ref/occ/instm/UIApplication/registerForRemoteNotifications

Are you using any third party push notification SDK? If so then usually methods in that SDK will do the registration and storing the token in their database.

Only thing that you have to control is to delay the call that is used to register for remote notifications

Pradeep K
  • 3,671
  • 1
  • 11
  • 15