0

The following code generally works but throws an SSL handshake failed (-9806) when the device is locked.

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
{
    NSString *roomID = [userInfo objectForKey:@"roomId"];
    if (roomID) {
        //tell firebase to update this conversation
        [self.fb updateChatRoomMessages:roomID withBlock:^(BOOL success) {                

           /*code gets to here as I can see that with breakpoints, 
            but before we get here we can see the SSL handshake
            error in console (only when phone is locked)*/

            handler(UIBackgroundFetchResultNewData);
        }];
    } else {
        handler(UIBackgroundFetchResultNoData);
    }
}

Now basically updateChatRoomMessages tries to talk to firebase but I assume the problem is with just about any network connection. Is there known any restriction of the sort?

Any ideas?

Update - rest of the code

(void)updateChatRoomMessages:(NSString *)roomID withBlock:(void (^)(BOOL))completionBlock{
        ChatRoomSummary *room = [[DataCollections shared] getChatRoomById:roomID];

        Firebase *ref = [[Firebase alloc] initWithUrl:[NSString stringWithFormat:@"%@/chatdata/messages/%@",
                                                       self.baseURL, roomID]];
        [ref observeSingleEventOfType:FEventTypeValue withBlock:^(FDataSnapshot *allMsgs) {
            dispatch_async(dispatch_get_main_queue(), ^{

                [room.messages removeAllObjects]; //clearing the list of messages so that we update it
                NSDictionary *dict = allMsgs.value;

                for(NSString *snapshot in [dict allKeys]) {
                    NSDictionary *currentSnapshot = [dict objectForKey:snapshot];
                    [currentSnapshot setValue:snapshot forKey:@"messageID"];
                    [[DataEventListener shared] onNewMessage:currentSnapshot forRoom:room preventNotification:YES];
                }

                [Utility notify:NOTIFY_NEW_ROOM];

                [self updateBadges:nil];

                if (completionBlock) {
                    completionBlock(YES);
                }
            });
        }];
}
Mark Camilleri
  • 130
  • 2
  • 11
  • Found this question which seems to report a very similar problem, http://stackoverflow.com/questions/21318200/cfnetwork-sslhandshake-failed-9806-error-using-nsurlsession-when-app-in-backg – Mark Camilleri Nov 26 '15 at 07:35
  • Mark, can you post the code in `updateChatRoomMessages` so we can see generally what you're doing? Are you using the REST client of the realtime client? What version of the realtime client are you using (if you're using the RT client), as well as what version of iOS? – Mike McDonald Dec 07 '15 at 18:56
  • Thanks Mike, I've added the rest of the code. It's just a value event. Am using the latest Firebase iOS SDK 2.4.3 and ios 9.1 The SSL handshake error only happens when device is locked, otherwise even if app is in background the above code works well – Mark Camilleri Dec 08 '15 at 13:52
  • So if it's using the iOS SDK, ATS shouldn't be a problem (we use websockets instead of HTTP), so it sounds to me like it's an issue with the connection being closed in the background (the OS can kill socket connections when an app is backgrounded). – Mike McDonald Dec 30 '15 at 01:50
  • Hey @MikeMcDonald thanks for your replies - yes ATS should be ok anyway as I allow the firebaseio domain including subdomains etc, and it is only misbehaving after the device is locked so must be related to backgrounded app status. have you ever encountered such a problem? surely lots of chat apps would require to talk to firebase while device is locked (on notification event) – Mark Camilleri Jan 27 '16 at 10:30

0 Answers0