Я настроил push-уведомление от firebase.Когда я отправляю его из консоли Firebase, он идет нормально, но когда я отправляю его из бэкэнда, ни один метод не вызывается, только ошибка в логах - FIRMessaging received data-message, but FIRMessagingDelegate's-messaging:didReceiveMessage: not implemented
То же нажатие работает на Android, но нев iOS.
Вот мой код:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (isGranted, err) in
if err != nil {
//Something bad Happend
} else {
UNUserNotificationCenter.current().delegate = self
Messaging.messaging().delegate = self
DispatchQueue.main.async {
application.registerForRemoteNotifications()
}
}
}
UIApplication.shared.registerForRemoteNotifications()
FirebaseApp.configure()
return true
}
public func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Swift.Void) {
let info = notification.request.content.userInfo
print(info)
}
func convertToJson(text: String) -> [String: Any]? {
if let data = text.data(using: .utf8) {
do {
return try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]
} catch {
print(error.localizedDescription)
}
}
return nil
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
// DO NOTHING
print(userInfo)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
// If you are receiving a notification message while your app is in the background,
print(userInfo)
}
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
let newToken = InstanceID.instanceID().token()
print(newToken)
let loggedUser = UserDefaults.standard
loggedUser.set(newToken, forKey: Constants.deviceToken)
connectToFCM()
}