{"action":"closed","issue":{"url":"https://api.github.com/repos/firebase/quickstart-ios/issues/94","repository_url":"https://api.github.com/repos/firebase/quickstart-ios","labels_url":"https://api.github.com/repos/firebase/quickstart-ios/issues/94/labels{/name}","comments_url":"https://api.github.com/repos/firebase/quickstart-ios/issues/94/comments","events_url":"https://api.github.com/repos/firebase/quickstart-ios/issues/94/events","html_url":"https://github.com/firebase/quickstart-ios/issues/94","id":176865571,"number":94,"title":"Unable to connect to FCM when in Sandbox ","user":{"login":"groovz","id":16528276,"avatar_url":"https://avatars.githubusercontent.com/u/16528276?v=3","gravatar_id":"","url":"https://api.github.com/users/groovz","html_url":"https://github.com/groovz","followers_url":"https://api.github.com/users/groovz/followers","following_url":"https://api.github.com/users/groovz/following{/other_user}","gists_url":"https://api.github.com/users/groovz/gists{/gist_id}","starred_url":"https://api.github.com/users/groovz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/groovz/subscriptions","organizations_url":"https://api.github.com/users/groovz/orgs","repos_url":"https://api.github.com/users/groovz/repos","events_url":"https://api.github.com/users/groovz/events{/privacy}","received_events_url":"https://api.github.com/users/groovz/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2016-09-14T10:00:37Z","updated_at":"2016-12-06T22:07:31Z","closed_at":"2016-12-06T22:07:31Z","body":"Hi\n\nI'm always receiving this error when opening the app and calling connectWithCompletion : \n\n> connectToFcm() > Unable to connect with FCM. Optional(Error Domain=No internet available, cannot connect to FIRMessaging Code=4 \"(null)\")\u001B[;\n\nWe actually have full wifi and internet connection in the device when trying to make this call but it always returns this error.\n\nThen 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\n\nhere's the AppDelegate relevant functions : \n\n`\n\n```\nfunc application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {\n\n    // Add observer for InstanceID token refresh callback (needed for GCM access token)\n    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.tokenRefreshNotification), name: kFIRInstanceIDTokenRefreshNotification, object: nil)\n\n    // configure Firebase\n    FIRApp.configure()\n\n    registerForNotifications(application)\n\n    return true\n    }\n\nprivate func registerForNotifications(application: UIApplication) {\n    let actionReply = UIMutableUserNotificationAction()\n    actionReply.activationMode = UIUserNotificationActivationMode.Background\n    actionReply.title = \"Reply\"\n    actionReply.identifier = NOTIFICATION_ACTION_REPLY\n    actionReply.destructive = false\n    actionReply.authenticationRequired = false // This will be true regardless the statement, because of activationMode = UIUserNotificationActivationMode.Foreground\n    actionReply.behavior = UIUserNotificationActionBehavior.TextInput\n\n    let actionIgnore = UIMutableUserNotificationAction()\n    actionIgnore.activationMode = UIUserNotificationActivationMode.Background\n    actionIgnore.title = \"Ignore\"\n    actionIgnore.identifier = NOTIFICATION_ACTION_IGNORE\n    actionIgnore.destructive = false\n    actionIgnore.authenticationRequired = false\n\n        let category = UIMutableUserNotificationCategory()\n        category.identifier = NOTIFICATION_MESSAGE_CATEGORY\n        category.setActions([actionReply, actionIgnore], forContext: UIUserNotificationActionContext.Default)\n        category.setActions([actionReply, actionIgnore], forContext: UIUserNotificationActionContext.Minimal)\n\n        let categories = NSSet(array: [category]) as! Set<UIUserNotificationCategory>\n        let types: UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Sound, UIUserNotificationType.Badge]\n        let settings = UIUserNotificationSettings(forTypes: types, categories: categories)\n\n        application.registerUserNotificationSettings(settings)\n}\n\nfunc tokenRefreshNotification(notification: NSNotification) {\n    if let refreshedToken = FIRInstanceID.instanceID().token() {\n        log.info(\"InstanceID token: \\(refreshedToken)\")            \n        saveTokenAndUpdateServer(refreshedToken, error: nil)\n\n        // Connect to FCM since connection may have failed when attempted before having a token.\n        connectToFcm()\n    }\n}\n\nfunc connectToFcm() {\n    FIRMessaging.messaging().connectWithCompletion { (error) in\n        if (error != nil) {\n            log.error(\"Unable to connect with FCM. \\(error)\")\n        } else {\n            log.info(\"Connected to FCM.\")\n        }\n    }\n}\n```\n\n`\n"}}
{"actor":{"display_login":"ianbarber"}}