0

Is there a way to prompt the user to enable push notifications when it actually makes sense? Put another way, instead of prompting the user to enable push notifications as soon as the app is launched for the first time (with code in app delegate), delay the prompt to after a specific point in the app (post walkthrough for example).

I have seen several apps that do that including Google Photos and Uber but I am not clear which piece of code actually triggers the on screen dialog and if I can place it anywhere in the app. I assume it is the following (in Swift):

UIApplication.sharedApplication().registerForRemoteNotifications()
let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)   
application.registerUserNotificationSettings(settings)
zevij
  • 2,416
  • 1
  • 23
  • 32
  • 1
    For a good user experience it's highly recommended to leave all messages related to system services *...would like to enable/send/use...* where they are. – vadian Mar 13 '16 at 09:47
  • 1
    I get that you should not fiddle with system driven settings but my question is driven by user feedback. Also, there are plenty of apps out there that do exactly what I'm after (Google photos is one such example). Effectively, it would be 'release the app w/o the property in plist, prompt the user, rewrite and save the plist'. Thoughts? – zevij Mar 13 '16 at 09:59
  • I guess we'll never know their thoughts... – Denny Apr 08 '19 at 14:30

2 Answers2

0

Put the following code anywhere in your app you think its right (i.e. other than in app delegate) to prompt the user to enable notifications:

UIApplication.sharedApplication().registerForRemoteNotifications()
let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)   
application.registerUserNotificationSettings(settings)

To handle the various scenarios you can follow this answer/thread.

Community
  • 1
  • 1
zevij
  • 2,416
  • 1
  • 23
  • 32
0

Actually this is the right code, which you can fire from wherever you want

let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
UIApplication.sharedApplication().registerForRemoteNotifications()
ivan123
  • 317
  • 2
  • 7