2016-08-23 108 views
12
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 

此問題已被問起before。但我仍然對如何解決這個問題感到不知所措。通知不起作用,我唯一的領導是行:Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"Firebase無法獲取APNS令牌Error Domain = com.firebase.iid Code = 1001「(null)」

我有雙重檢查,我上傳了正確的.p12文件到firebase。我已經進入了目標 - > - > Capabilities->背景Modes->remote-notificationsON 我有雙重檢查,我bundleID的GoogleService-Info.plist的匹配

這裏是我的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.") 
     } 
    } 
} 

我的猜測是,它應該在沒有最後兩種方法的情況下工作,但無論如何我都會將它們放在那裏(根據打印聲明,它看起來不像被稱爲)。

我打電話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() 
} 

而且我可以看到deviceToken打印在控制檯上。但我仍然遇到這個FireBase問題。我可以檢查其他事情的任何想法?

+0

你解決這個問題? – Dmitry

+0

不,我最終放棄了Firebase for iOS並使用了PyAPNS(我的後端是用django/Python編寫的)。 –

回答

2

我曾嘗試構建基於iOS(Swift)的Firebase/Quickstart-iOS示例的簡單應用程序,並且我遇到了同樣的問題:Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"

當應用程序在後臺時,我無法收到通知。 所以,我已經找到解決方案,在這裏爲我工作: https://github.com/firebase/quickstart-ios/issues/103

基本上,我沒有添加這個方法:

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

...這行代碼:

application.registerForRemoteNotifications() 

顯然,例如用Objective-C正常工作,但例如斯威夫特缺少一些代碼片段,並預期它不工作...

+0

爲我工作,謝謝! – norbDEV

0

嘗試將Firebase/Core更新到v3.4.4,它爲我解決了意想不到的錯誤。否則,請儘量避免撥打unregisterForRemoteNotifications。此通話後,您無法再註冊該設備以推送通知。另外,請嘗試在info.plist文件中設置FirebaseAppDelegateProxyEnabledNO。我認爲他們的方法會變得錯誤。

0

調用此方法您將獲得設備令牌。我可以看到打印在控制檯上的deviceToken

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

你應該調用這個方法,你的第一個屏幕會出現。在appdelegate之後。 –

+0

在viewdidload()裏面添加這個方法 –

相關問題