Reputation: 9386
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
This question has been asked before. But I am still at a loss for how to fix it. Notifications aren't working and the only lead I have is the line: Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"
I have double checked that I uploaded the correct .p12 files into firebase. I have gone into Target->->Capabilities->Background Modes->remote-notifications
and ON
I have double checked that my bundleID matches the GoogleService-Info.plist
Here is my 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.")
}
}
}
My guess is that it should work without those last two methods, but I put them in there anyway (according to the print statements it doesn't look like they are being called).
I call 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()
}
And I can see the deviceToken printed on the console. But I still get this FireBase issue. Any ideas of other things I can check?
Upvotes: 13
Views: 6429
Reputation: 1
Call this method you will get device token. And I can see the deviceToken
printed on the console.
dispatch_async(dispatch_get_main_queue(),
{
global.appdel.tokenRefreshNotification()
})
Upvotes: 0
Reputation: 2788
Try updating Firebase/Core to v3.4.4, it fixed unexpected errors for me. Otherwise try to avoid calling unregisterForRemoteNotifications
. After this call, you can't register the device anymore to push notifications. Also, try setting FirebaseAppDelegateProxyEnabled
to NO
in your info.plist file. I think there are bugs with their method swizzling.
Upvotes: 0
Reputation: 2796
I did try to build simple app based on Firebase/Quickstart-iOS example for iOS (Swift) and I had the same issue: Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"
.
I was not able to receive notification while app was in background. So, I've found solution that worked for me here: https://github.com/firebase/quickstart-ios/issues/103
Basically, I did add this method:
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
print("Handle push from background or closed" );
print("%@", response.notification.request.content.userInfo);
}
... and this line of code:
application.registerForRemoteNotifications()
Apparently, example written in Objective-C works fine, but example in Swift is missing some pieces of code and it doesn't work as expected...
Upvotes: 2