قالب وردپرس درنا توس
Home / IOS Development / IOS – Why aren't messages sent by fire base on my phone?

IOS – Why aren't messages sent by fire base on my phone?



I followed this tutorial and after implementing all the code, I tried to create and send a warning from the Firebase message console. The problem is, I don't receive the message on my device.

What's my problem here?

Bellow is my app delegate

      @UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

was window: UIWindow?
la gcmMessageIDKey = "gcm.message_idd"

func application (_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after program start.
FirebaseApp.configure ()

if # available (iOS 10.0, *) {
// For IOS 1
0 screen notification (sent via APNS) UNUserNotificationCenter.current (). Delegate = self la authOptions: UNAuthorizationOptions = [.alert, .badge, .sound] UNUserNotificationCenter.current (). RequestAuthorization ( options: authOptions, completionHandler: {_, _ in}) } other { leave settings: UIUserNotificationSettings = UIUserNotificationSettings (types: [.alert, .badge, .sound] categories: null) application.registerUserNotificationSettings (settings) } Messaging.messaging (). Delegate = self application.registerForRemoteNotifications () return true } func application (_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) { // If you receive a notification message while your app is in the background, // This callback will not be fired until the user's cranes in the notification start the application. // TODO: Manage alert data // With swizzling deactivated you must let Messages know about the message, for Analytics // Messaging.messaging (). AppDidReceiveMessage (userInfo) // Print message ID. if leave messageID = userInfo [gcmMessageIDKey] { print ("Message ID: (messageID)") } // Print full message. print (Userinfo) } func program (_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], FetchCompletionHandler completingHandler: @escaping (UIBackgroundFetchResult) -> Fat) { // If you receive a notification message while your app is in the background, // This callback will not be fired until the user's cranes in the notification start the application. // TODO: Manage alert data // With swizzling deactivated you must let Messages know about the message, for Analytics // Messaging.messaging (). AppDidReceiveMessage (userInfo) // Print message ID. if leave messageID = userInfo [gcmMessageIDKey] { print ("Message ID: (messageID)") } // Print full message. print (Userinfo) completionHandler (UIBackgroundFetchResult.newData) } } @ available (iOS 10, *) extension AppDelegate: UNUserNotificationCenterDelegate { // Receive displayed alerts for iOS 10 devices. func userNotificationCenter (_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Valid) { la userInfo = notification.request.content.userInfo // With swizzling deactivated you must let Messages know about the message, for Analytics // Messaging.messaging (). AppDidReceiveMessage (userInfo) // Print message ID. if leave messageID = userInfo [gcmMessageIDKey] { print ("Message ID: (messageID)") } // Print full message. print (Userinfo) // Change this to the preferred presentation option completionHandler ([]) } func userNotificationCenter (_ center: UNUserNotificationCenter, didreceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { la userInfo = response.notification.request.content.userInfo // Print message ID. if leave messageID = userInfo [gcmMessageIDKey] { print ("Message ID: (messageID)") } // Print full message. print (Userinfo) completionHandler () } } extension AppDelegate: MessagingDelegate { func messaging (_ messaging: Messages, doneReceiveRegistrationToken fcmToken: String) { print ("Firebase registration token: (fcmToken)") la dataDict: [String: String] = ["token": fcmToken] NotificationCenter.default.post (name: Notification.Name ("FCMToken"), object: null, userInfo: dataDict) // TODO: Send the Token if necessary to the application server. // Note: This callback is fired at each startup of the app and when a new token is generated. } func messaging (_ messaging: Messages, Recreative remoteMessage: MessagingRemoteMessage) { print ("Message data", remoteMessage.appData) } }

How do I fix this problem? What am I doing wrong that prevents me from receiving the notification?

  • I have all the code reviewed in my app delegative
  • I go to the fire message, create a new message and press publish
  • I run the app on the ring and see if it is running and it never appears (The app is in the background )

Source link