I have integrated Firebase
into my project and I think I have followed all the steps required for generating push notifications within the app. I have also tested the push notifications by sending some dummy notifications from the Firebase console.
This is the tutorial I entirely followed.
Now my questions are..
- How will I get the
FCM ID
so that I can send it in my api call. - When a push notification comes, where do I handle it..?
- Where do I mention things like when to receive the notifications and the actions to take while tapping on notifications..?
EDIT 1
So this is all the code I have for handling push notifications...
In didFinishLaunchingWithOptions
...
if #available(iOS 10.0, *) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
// For iOS 10 data message (sent via FCM
Messaging.messaging().delegate = self
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
FirebaseApp.configure()
And then,
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
let token = Messaging.messaging().fcmToken
print("FCM token: \(token ?? "")")
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]){
print("userInfo:-> \(userInfo)")
}