Files
omnivore/apple/OmnivoreKit/Sources/Utils/PushNotificationUtils.swift
2022-02-11 09:24:33 -08:00

20 lines
630 B
Swift

import Foundation
import UserNotifications
public extension UNUserNotificationCenter {
/// Shows prompt to user to allow push notifications
/// If previously denied then no prompt is shown
func requestAuth() {
// Only the first call to this function will result in a prompt
// If user denies the first time then that gets saved to device settings
requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in
guard error != nil else { return }
if !granted {
// Maybe show instructions to change in settings?
print("user denied push notifications")
}
}
}
}