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);
                }
            });
        }];
}