I've currently working with notifications and I've not succeed to get any notification from the Firebase FCM.
The podfile configuration is:
target 'Project' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for Project
pod 'Firebase/Core'
pod 'Firebase/Messaging'
end
I've activated Push Notifications
and Remote Notifications
from the Background fetches
and already read the another topic in stackoverflow
which is currently similar, in here
I want to share my AppDelegate codes with you but firstly I have to say the documents of the Google for push notifications seems a bit confusing because there are so many overrided method in here and every tutorial has different way to accomplish to receive a notification.
I've imported these
import Firebase
import FirebaseInstanceID
import UserNotifications
import FirebaseMessaging
Then there is the delegations
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate{
...
}
Then here is the willFinishLaunchWithOptions method
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
FirebaseApp.configure()
Messaging.messaging().delegate = self
if #available(iOS 10.0, *) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
// For iOS 10 data message (sent via FCM
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
return true
}
And here is the Messaging
delegate functions.
func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
print("MEssage -> \(remoteMessage.appData)")
}
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
print("Firebase registration token: \(fcmToken)")
}
That function was in the Firebase documentation for setting apns token.
func application(application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
Messaging.messaging().apnsToken = deviceToken as Data
}
I've sent hundreds of notifications from the FCM' and it sent successfully on the server side but when i log the received message there is nothing to income data.
If you ask that why I implement configuration in willFinish
function there was a note in the documentation like that.
For devices running iOS 10 and above, you must assign the
UNUserNotificationCenter's delegate property and FIRMessaging's
delegate property. For example, in an iOS app, assign it in the
applicationWillFinishLaunchingWithOptions: or
applicationDidFinishLaunchingWithOptions: method of the app delegate.
I would appreciate that any help from you, because its hard to see what's wrong with it for now.