web-dev-qa-db-fra.com

Firebase Impossible d'extraire le domaine d'erreur du jeton APNS = com.firebase.iid Code = 1001 "(null)"

2016-08-22 18:34:50.108: <FIRInstanceID/WARNING> FIRInstanceID AppDelegate proxy enabled, will swizzle app delegate remote notification handlers. To disable add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO
2016-08-22 18:34:50.106 YAKKO[4269:] <FIRAnalytics/INFO> To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see ...)
2016-08-22 18:34:50.114: <FIRInstanceID/WARNING> Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"
2016-08-22 18:34:50.120: <FIRMessaging/INFO> FIRMessaging library version 1.1.1
2016-08-22 18:34:50.125: <FIRMessaging/WARNING> FIRMessaging AppDelegate proxy enabled, will swizzle app delegate remote notification receiver handlers. Add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO
2016-08-22 18:34:50.144 YAKKO[4269:] <FIRAnalytics/INFO> Successfully created Firebase Analytics App Delegate Proxy automatically. To disable the proxy, set the flag FirebaseAppDelegateProxyEnabled to NO in the Info.plist
2016-08-22 18:34:50.188 YAKKO[4269:] <FIRAnalytics/INFO> Firebase Analytics enabled

Cette question a été posée avant . Mais je ne sais toujours pas comment y remédier. Les notifications ne fonctionnent pas et la seule piste que j'ai est la ligne: Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"

J'ai vérifié deux fois que j'avais chargé les fichiers .p12 corrects dans Firebase. Je suis entré dans Target -> -> Fonctionnalités-> Modes d'arrière-plan -> remote-notifications et ON J'ai vérifié que mon bundleID correspond à GoogleService-Info.plist.

Voici mon AppDelegate.Swift

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
        FIRApp.configure()
        ....
}

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
    print("DEVICE TOKEN = \(deviceToken)")
    FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Sandbox)
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
                 fetchCompletionHandler completionHandler: (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
    FIRMessaging.messaging().appDidReceiveMessage(userInfo)

    // Print message ID.
    print("Message ID: \(userInfo["gcm.message_id"]!)")

    // Print full message.
    print("%@", userInfo)
}
func tokenRefreshNotification(notification: NSNotification) {
    // NOTE: It can be nil here
    let refreshedToken = FIRInstanceID.instanceID().token()
    print("InstanceID token: \(refreshedToken)")

    connectToFcm()
}

func connectToFcm() {
    FIRMessaging.messaging().connectWithCompletion { (error) in
        if (error != nil) {
            print("Unable to connect with FCM. \(error)")
        } else {
            print("Connected to FCM.")
        }
    }
}

Mon hypothèse est que cela devrait fonctionner sans ces deux dernières méthodes, mais je les ai quand même incluses (selon les déclarations imprimées, il ne semble pas qu'elles soient appelées). 

J'appelle registerForRemoteNotifications:

static func registerForNoties(){

    let notificationTypes: UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
    let pushNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)
    UIApplication.sharedApplication().registerUserNotificationSettings(pushNotificationSettings)
    UIApplication.sharedApplication().registerForRemoteNotifications()
}

Et je peux voir le deviceToken imprimé sur la console. Mais j'ai toujours ce problème avec FireBase. Des idées d'autres choses que je peux vérifier?

12
Chase Roberts

J'ai essayé de créer une application simple basée sur l'exemple Firebase/Quickstart-iOS pour iOS (Swift) et j'avais le même problème: Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)".

Je n'ai pas pu recevoir de notification alors que l'application était en arrière-plan. J'ai donc trouvé une solution qui fonctionnait pour moi ici: https://github.com/firebase/quickstart- ios/numéros/103

Fondamentalement, j'ai ajouté cette méthode:

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
            print("Handle Push from background or closed" );
            print("%@", response.notification.request.content.userInfo);
        }

... et cette ligne de code: 

application.registerForRemoteNotifications()

Apparemment, les exemples écrits en Objective-C fonctionnent bien, mais des exemples dans Swift manquent quelques morceaux de code et cela ne fonctionne pas comme prévu ...

2
Dmitry

Essayez de mettre à jour Firebase/Core vers la v3.4.4, cela corrigeait les erreurs inattendues. Sinon, essayez d'éviter d'appeler unregisterForRemoteNotifications. Après cet appel, vous ne pouvez plus enregistrer l'appareil dans les notifications Push. Essayez également de définir FirebaseAppDelegateProxyEnabled sur NO dans votre fichier info.plist. Je pense qu'il y a des insectes avec leur méthode qui grésille.

0
Lucas Chwe

Appelez cette méthode, vous obtiendrez un jeton de périphérique. Et je peux voir la deviceToken imprimée sur la console.

dispatch_async(dispatch_get_main_queue(),
{
     global.appdel.tokenRefreshNotification()
})
0
Paresh Prajapati