0

Es gibt nichts in dieser App. Ich hatte Verbindung mit Firebase für die Benachrichtigung. mein CodeSwift3: Keine Remote-Benachrichtigung erhalten

import UIKit 
import UserNotifications 
import FirebaseMessaging 
import Firebase 

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate { 

    var window: UIWindow? 
    let gcmMessageIDKey = "gcm.message_id" 

    func application(_ application: UIApplication, 
        didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 

     FirebaseApp.configure() 

     // [START set_messaging_delegate] 
     Messaging.messaging().delegate = self 
     // [END set_messaging_delegate] 
     // Register for remote notifications. This shows a permission dialog on first run, to 
     // show the dialog at a more appropriate time move this registration accordingly. 
     // [START register_for_notifications] 
     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 }) 
     } else { 
      let settings: UIUserNotificationSettings = 
       UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil) 
      application.registerUserNotificationSettings(settings) 
     } 

     application.registerForRemoteNotifications() 

     // [END register_for_notifications] 
     return true 
    } 

    // [START receive_message] 
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) { 
     // If you are receiving a notification message while your app is in the background, 
     // this callback will not be fired till the user taps on the notification launching the application. 
     // TODO: Handle data of notification 
     // With swizzling disabled you must let Messaging know about the message, for Analytics 
     // Messaging.messaging().appDidReceiveMessage(userInfo) 
     // Print message ID. 
     if let messageID = userInfo[gcmMessageIDKey] { 
      print("Message ID: \(messageID)") 
     } 

     // Print full message. 
     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, 
     // this callback will not be fired till the user taps on the notification launching the application. 
     // TODO: Handle data of notification 
     // With swizzling disabled you must let Messaging know about the message, for Analytics 
     // Messaging.messaging().appDidReceiveMessage(userInfo) 
     // Print message ID. 
     if let messageID = userInfo[gcmMessageIDKey] { 
      print("Message ID: \(messageID)") 
     } 

     // Print full message. 
     print(userInfo) 

     completionHandler(UIBackgroundFetchResult.newData) 
    } 
    // [END receive_message] 
    func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { 
     print("Unable to register for remote notifications: \(error.localizedDescription)") 
    } 

    // This function is added here only for debugging purposes, and can be removed if swizzling is enabled. 
    // If swizzling is disabled then this function must be implemented so that the APNs token can be paired to 
    // the FCM registration token. 
    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { 
     print("APNs token retrieved: \(deviceToken)") 

     // With swizzling disabled you must set the APNs token here. 
     // Messaging.messaging().apnsToken = deviceToken 
    } 
} 

// [START ios_10_message_handling] 
@available(iOS 10, *) 
extension AppDelegate : UNUserNotificationCenterDelegate { 

    // Receive displayed notifications for iOS 10 devices. 
    func userNotificationCenter(_ center: UNUserNotificationCenter, 
           willPresent notification: UNNotification, 
           withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { 
     let userInfo = notification.request.content.userInfo 

     // With swizzling disabled you must let Messaging know about the message, for Analytics 
     // Messaging.messaging().appDidReceiveMessage(userInfo) 
     // Print message ID. 
     if let messageID = userInfo[gcmMessageIDKey] { 
      print("Message ID: \(messageID)") 
     } 

     // Print full message. 
     print(userInfo) 

     // Change this to your preferred presentation option 
     completionHandler([]) 
    } 

    func userNotificationCenter(_ center: UNUserNotificationCenter, 
           didReceive response: UNNotificationResponse, 
           withCompletionHandler completionHandler: @escaping() -> Void) { 
     let userInfo = response.notification.request.content.userInfo 
     // Print message ID. 
     if let messageID = userInfo[gcmMessageIDKey] { 
      print("Message ID: \(messageID)") 
     } 

     // Print full message. 
     print(userInfo) 

     completionHandler() 
    } 
} 
// [END ios_10_message_handling] 

extension AppDelegate : MessagingDelegate { 
    // [START refresh_token] 
    func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) { 
     print("Firebase registration token: \(fcmToken)") 
    } 
    // [END refresh_token] 
    // [START ios_10_data_message] 
    // Receive data messages on iOS 10+ directly from FCM (bypassing APNs) when the app is in the foreground. 
    // To enable direct data messages, you can set Messaging.messaging().shouldEstablishDirectChannel to true. 
    func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) { 
     print("Received data message: \(remoteMessage.appData)") 
    } 
    // [END ios_10_data_message] 
} 

das ist, was ich in der Konsole

2017-08-28 19:37:01.204266-0400 newnotifica3[28588:10713078] [Firebase/Analytics][I-ACS003016] Firebase Analytics App Delegate Proxy is disabled. To log deep link campaigns manually, call the methods in FIRAnalytics+AppDelegate.h. 
2017-08-28 19:37:01.204 newnotifica3[28588] <Warning> [Firebase/Analytics][I-ACS003016] Firebase Analytics App Delegate Proxy is disabled. To log deep link campaigns manually, call the methods in FIRAnalytics+AppDelegate.h. 
2017-08-28 19:37:01.264081-0400 newnotifica3[28588:10713076] [Firebase/Analytics][I-ACS023007] Firebase Analytics v.4001000 started 
2017-08-28 19:37:01.264 newnotifica3[28588] <Notice> [Firebase/Analytics][I-ACS023007] Firebase Analytics v.4001000 started 
2017-08-28 19:37:01.264507-0400 newnotifica3[28588:10713076] [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see) 
2017-08-28 19:37:01.264 newnotifica3[28588] <Notice> [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see) 
FCM token: fstLqWX6ZjA:APA91bE6PovZpdgL0l0AcsEcL_rXn1heAcNLzG6rQhIxMflkVRz32OcAilYN5-bpLNrYTaKK5xtzfdHrfU63T9Tpkb-SG2_mx8-YYtbwlQUyGWxG4V_QuozNVUVNq9EH-BstecIFgaTZ 
APNs token retrieved: 32 bytes 
2017-08-28 19:37:01.305018-0400 newnotifica3[28588:10713081] [Firebase/Analytics][I-ACS023012] Firebase Analytics enabled 
2017-08-28 19:37:01.305 newnotifica3[28588] <Notice> [Firebase/Analytics][I-ACS023012] Firebase Analytics enabled 
2017-08-28 19:37:01.315306-0400 newnotifica3[28588:10713076] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles 
2017-08-28 19:37:01.316763-0400 newnotifica3[28588:10713076] [MC] Reading from public effective user settings. 

ich Benachrichtigung erlauben kann, wenn es zuerst installiert bin immer aber wenn ich Benachrichtigung oder Meldung von Feuerbasis senden manuell zu überprüfen, ob es funktioniert oder nicht, aber ich kann sehen, dass die Nachricht erfolgreich gesendet wird nichts auf meinem Handy weder in einer Konsole.

bitte helfen Sie mir aus.

+0

Vor Irgendwann läuft alles gut, aber jetzt weiß ich nicht, was passiert ist, hört auf, eine Benachrichtigung sogar manuell zu bekommen ... bitte hilf mir –

Antwort

0

Es gibt einige Änderungen, wie die APNS deviceToken abgerufen werden.