Add the Nudge notification handlers to your AppDelegate
Add the import to the top of your AppDelegate file
AppDelegate.swift
import nudge
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
}
Note: If you are using a newer SwiftUI application you can incorporate these AppDelegate Methods using @UIApplicationDelegateAdaptor from your main App struct
Then, start by editing the didFinishLaunchingWithOptions method
Add the following nudge method to register your app to receive notifications:
UNUserNotificationCenter.current().delegate = self
try? Nudge.registerForPushNotifications()
application.registerForRemoteNotifications()
NOTE: this method is only available for iOS 10 or higher. If you'd like to handle the case where your user is below iOS 10, you can do so by catching the following error:
UNUserNotificationCenter.current().delegate = self
do {
try Nudge.registerForPushNotifications()
} catch Nudge.NudgeErrors.unsupportediOSVersion {
print("Unsupported iOS version, please upgrade.")
} catch {
print("Unexpected error when trying to register for push notifications.")
}
application.registerForRemoteNotifications()Next, we need to know when your app has finished registering
Add the entire following method towards the bottom of your AppDelegate class:
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Nudge.onRegisteredForNotifications(deviceToken: deviceToken)
} We also need to know in case anything goes wrong
Add this entire last method after the one you just added:
func application(_ application: UIApplication,
didFailToRegisterForRemoteNotificationsWithError error: Error) {
Nudge.onFailedToRegisterForNotifications(error:error)
}
Comments
0 comments
Article is closed for comments.