[ad_1]
I’m working on push notification and I’m wondering like when user click on export pdf button on app it will get the push notification and it get the url of pdf through notification and this url will append in backend api.Can anyone tell me how I can implement this one.I’ve already implemented one type of push notification when user scan the object it gets the push notification.But I don’t know how to handle the multiple type of cases using push notification.
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
setupForPushNotification()
return true
}
}
extension AppDelegate: UNUserNotificationCenterDelegate {
func setupForPushNotification() {
UNUserNotificationCenter.current().delegate = self
UIApplication.shared.registerForRemoteNotifications()
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(options: authOptions) { [weak self] (granted, error) in
guard error == nil else {
print(error!.localizedDescription)
return
}
guard granted else { return }
self?.Notifications()
}
}
func Notifications() {
UNUserNotificationCenter.current().Notifications { settings in
guard settings.authorizationStatus == .authorized else { return }
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().delegate = self
Messaging.messaging().apnsToken = deviceToken
updateFirestorePushTokenIfNeeded()
}
}
extension AppDelegate: MessagingDelegate {
func updateFirestorePushTokenIfNeeded() {
Messaging.messaging().token { token, error in
if let error = error {
} else if let token = token {
UserDefaults.set(fcmToken: token)
}
}
}
}
extension AppDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
PushNotificationManager.notificationInForground(userInfo)
completionHandler([.alert, .badge, .sound])
}
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
PushNotificationManager.notificationInForground(userInfo)
}
}
[ad_2]
Source link