2017-02-10 5 views
2

aufgerufen Zuerst einmal, ich habe kein Problem für FCM, Firebase-Token ist nie null jedes Mal tokenRefreshNotification aufgerufen wird. Aber nachdem ich Google Analytics hinzugefügt habe, habe ich ein seltsames Problem für Firebase-Token bekommen. Jedes Mal, wenn ich auszuschalten und auf Benachrichtigung in meinen App-Einstellungen verwendetFirebase-Token ist Null und Token-Aktualisierung wird kontinuierlich in meinem testFlight

UIApplication.shared.registerForRemoteNotifications()

meine tokenRefreshNotification kontinuierlich genannt wird, und es wird Looping nicht aufhören, bis ich in der Nähe zwingen, meine apps. Zuerst stürzt meine App ab, und als ich versuche, sie mit NsLog zu verfolgen, habe ich festgestellt, dass das Firebase-Token null ist. Das Problem tritt nur auf, wenn ich meine von TestFlight/production installierten Apps verwende. Wenn ich es von meinem Xcode-Builder aus teste, ist das Firebase-Token nur einmal null, aber der zweite Aufruf, das Firebase-Token, existiert und es funktioniert nicht mehr.

Für Google Analytics funktioniert es gut und in meinem GoogleService-info.plist, habe ich IS_ANALYTICS_ENABLED auf YES und IS_GCM_ENABLED auch auf YES gesetzt. Für die anderen, IS_ADS_ENABLED = YES, IS_APPINVITE_ENABLED = NO und IS_SIGNIN_ENABLED = YES

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

     NotificationCenter.default.addObserver(self, selector: #selector(self.registerNotification), name: NSNotification.Name(rawValue: "registerNotification"), object: nil) 
     NotificationCenter.default.addObserver(self, selector: #selector(self.tokenRefreshNotification(_:)), name: .firInstanceIDTokenRefresh, object: nil) 
     setupGoogleAnalytics() 
     return true 
} 
//when firebase token is null, this function is working continously until my firebase token is exist 
func tokenRefreshNotification(_ notification: Notification) { 
    print("token Refresh") 
    if FIRInstanceID.instanceID().token() == nil{ 
     NSLog("firebase token is null") 
    } 

    if (UserDefaults.standard.object(forKey: "id") != nil) && FIRInstanceID.instanceID().token() != nil{ 
     FIRInstanceID.instanceID().getWithHandler({ (instanceID, error) in 
      NSLog("instanceID: \(instanceID!)") 
      //save firebase token to my database, sorry i can`t show it 
     }) 
    } 

    // Connect to FCM since connection may have failed when attempted before having a token. 
    connectToFcm()   
} 

Hinweis: Beim ersten Start, ich rief meinen RegisterForRemoteNotifications, bei Testflug Version, wenn tokenRefreshNotification genannt wird, ist die Feuerbasis Token null, aber der zweite Aufruf, Firebase-Token ist vorhanden, also könnte es aufhören. Aber wenn ich meine App von Xcode aus starte, ist der erste Aufruf erfolgreich, weil das Firebase-Token nicht null ist.

Antwort

4

ich habe es herausgefunden! Ändere einfach ANPS Type Token von Sandbox zu Unknown!

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {   
    // With swizzling disabled you must set the APNs token here. 
    FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.unknown) 
} 
+0

<3 Ich dachte, ich wäre der einzige. – Warpling

+0

Hallo kann ich erklären, warum FIRInstanceIDAPNSTokenType.unknown aber nicht FIRInstanceIDAPNSTokenType.prod verwenden? –

+0

wie ich weiß, kann unbekannter Typ anpassungsfähig sein, es kann für Entwicklung oder Produktion verwendet werden –

Verwandte Themen