-
-
Save shirishbankar1/3e235910dd6f4924cea1a0ab4d694f0f to your computer and use it in GitHub Desktop.
APNS on Simulator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import UserNotifications | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate { | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
// Override point for customization after application launch. | |
UNUserNotificationCenter.current().delegate = self | |
UNUserNotificationCenter.current() | |
.requestAuthorization(options: [.alert, .sound, .badge]) { | |
[weak self] granted, error in | |
print("Permission granted: \(granted)") | |
guard granted else { return } | |
UNUserNotificationCenter.current().getNotificationSettings { settings in | |
print("Notification settings: \(settings)") | |
guard settings.authorizationStatus == .authorized else { return } | |
DispatchQueue.main.async { | |
UIApplication.shared.registerForRemoteNotifications() | |
} | |
} | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment