Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barbaramartina/d1bb2a3e1baa57e22c4cea215ff531a9 to your computer and use it in GitHub Desktop.
Save barbaramartina/d1bb2a3e1baa57e22c4cea215ff531a9 to your computer and use it in GitHub Desktop.
How to register your app for push notifications in Swift 3
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// In iOS 8 and later, apps that use either local or remote notifications must register the types of user interactions the app supports. Apps can ask to badge icons, display alert messages, or play sounds. When you request any of these interaction types, the system checks the types of interactions the user has allowed for your app. If the user has disallowed a particular type of interaction, the system ignores attempts to interact with the user in that way.
// The user can change the notification settings for your app at any time using the Settings app. Because settings can change, always call the registerUserNotificationSettings: at launch time and use the application:didRegisterUserNotificationSettings: method to get the response.
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert]) { (granted, error) in
//TODO: process to match your app logic
}
application.registerForRemoteNotifications()
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment