Unable to connect to FCM when in Sandbox
Hi
I'm always receiving this error when opening the app and calling connectWithCompletion :
connectToFcm() > Unable to connect with FCM. Optional(Error Domain=No internet available, cannot connect to FIRMessaging Code=4 "(null)")[;
We actually have full wifi and internet connection in the device when trying to make this call but it always returns this error.
Then when going to the background and coming back in didBecomeActive we have another call to connectWithCompletion which never calls it's completion. from this point it does not matter how many times we go to the background and come back it won't call the completion
here's the AppDelegate relevant functions :
`
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Add observer for InstanceID token refresh callback (needed for GCM access token)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.tokenRefreshNotification), name: kFIRInstanceIDTokenRefreshNotification, object: nil)
// configure Firebase
FIRApp.configure()
registerForNotifications(application)
return true
}
private func registerForNotifications(application: UIApplication) {
let actionReply = UIMutableUserNotificationAction()
actionReply.activationMode = UIUserNotificationActivationMode.Background
actionReply.title = "Reply"
actionReply.identifier = NOTIFICATION_ACTION_REPLY
actionReply.destructive = false
actionReply.authenticationRequired = false // This will be true regardless the statement, because of activationMode = UIUserNotificationActivationMode.Foreground
actionReply.behavior = UIUserNotificationActionBehavior.TextInput
let actionIgnore = UIMutableUserNotificationAction()
actionIgnore.activationMode = UIUserNotificationActivationMode.Background
actionIgnore.title = "Ignore"
actionIgnore.identifier = NOTIFICATION_ACTION_IGNORE
actionIgnore.destructive = false
actionIgnore.authenticationRequired = false
let category = UIMutableUserNotificationCategory()
category.identifier = NOTIFICATION_MESSAGE_CATEGORY
category.setActions([actionReply, actionIgnore], forContext: UIUserNotificationActionContext.Default)
category.setActions([actionReply, actionIgnore], forContext: UIUserNotificationActionContext.Minimal)
let categories = NSSet(array: [category]) as! Set<UIUserNotificationCategory>
let types: UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Sound, UIUserNotificationType.Badge]
let settings = UIUserNotificationSettings(forTypes: types, categories: categories)
application.registerUserNotificationSettings(settings)
}
func tokenRefreshNotification(notification: NSNotification) {
if let refreshedToken = FIRInstanceID.instanceID().token() {
log.info("InstanceID token: \(refreshedToken)")
saveTokenAndUpdateServer(refreshedToken, error: nil)
// Connect to FCM since connection may have failed when attempted before having a token.
connectToFcm()
}
}
func connectToFcm() {
FIRMessaging.messaging().connectWithCompletion { (error) in
if (error != nil) {
log.error("Unable to connect with FCM. \(error)")
} else {
log.info("Connected to FCM.")
}
}
}
`
Worth metioning that I'm also getting this print as the app starts :
Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001
(maybe this is the actual error)
and I'm using swizzling (I didn't add the FirebaseAppDelegateProxyEnabled key to my info.plist)
Hi. I am having the same problem. I am not receiving the notifications on background on ios 10. And I am receiving this error:
Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"
I have the same...
Same issue here:
Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"
I try with new quickstart-ios updating my cocoapods:
# Firebase Cloud Messaging (FCM)
use_frameworks!
platform :ios, '10.0'
pod 'Firebase', '~> 3.6'
pod 'FirebaseMessaging', '~> 1.2.0'
target 'FCM' do
end
target 'FCMSwift' do
end
target 'FCMTests' do
end
And then, I change the bundle identifier to my bundle identifier and putting my GoogleService-Info.plist and works...
But, I tried to integrate FCM in my React Native application, same bundler identifier and GoogleService-Info.plist and I getting de "Failed to fetch APNS token Error".
React Native is based in Objective-C iOS project.
Hi Sir-gon,
I also tried the new quickstart-ios updating my cocoapods. And I generate a new identifier with new profiles, and I am still getting these errors:
2016-09-20 13:04:31.104: <FIRInstanceID/WARNING> Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)" 2016-09-20 13:04:31.173: <FIRInstanceID/WARNING> Failed to fetch APNS token Error Domain=NSCocoaErrorDomain Code=3000
My Xcode version is: Version 8.0 (8A218a)
I am trying the Firebase support, but no luck until now.
I found a solution to my problem:
Go to your PROJECT->TARGET->CAPABILITIES
Disable and Enable again the Push Notification item (OFF->ON).
The message: Failed to fetch APNS token Error Domain=NSCocoaErrorDomain Code=3000 went away. The message: Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 is still appearing.
But I am now able to receive the push on background. I hope to help anyone who is passing with this problem.
I noticied some connectivity issue due i'm behind a corporate proxy server... But, I change my network to use only 3g data network (no restrictions) and disabling wifi.
I fully removed the app before testing anyone:
Testing the FCM Example
Now i'm getting notifications in the background too, but still appearing "Unable to connect to FCM. Error Domain=com.google.fcm Code=501 "(null)" "...
Testing my app with same bundle identifier and .plist Same thing. But I noticied the token call was "asynchronous" (?) because the call to channel subscription was too fast and "Firebase InstanceID token" was not acquired at this time. In a second run I have a cached token (?) and now can receive notification in the background.
In the both tests, I'm getting the alert asking me for notification permissions, and I press "yes". Now necessary manually raise the notification? (I prefer it that way, but would not be bad that an example should be included).
I'm using latest Xcode 8.0 too, and an iPhone 5 as a physical device, with iOS 10.
I have seen these (different?) errors too:
Unable to connect to FCM. Error Domain=com.google.fcm Code=501 "(null)" Unable to connect to FCM. Error Domain=com.google.fcm Code=1001 "(null)" Unable to connect to FCM. Error Domain=com.google.fcm Code=2001 "(null)"
@groovz is this still an issue for you?
Also on Xcode 8 push notification entitlements are required, the sample has been updated to address this.
Thanks for the info.
Em terça-feira, 11 de outubro de 2016, Arthur Thompson < [email protected]> escreveu:
@groovz https://github.com/groovz is this still an issue for you?
Also on Xcode 8 push notification entitlements are required, the sample has been updated to address this.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/firebase/quickstart-ios/issues/94#issuecomment-253044184, or mute the thread https://github.com/notifications/unsubscribe-auth/AMExufTyMkYf1PdV06CmQMnMEDLlCkdTks5qy_iRgaJpZM4J8mX1 .
Marcel Ricardo Rocco e-mail: [email protected] [email protected]