以下代码通常可以正常工作,但在设备被锁定时会引发SSL握手失败(-9806)。
- (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);
}
}
现在基本上updateChatRoomMessages试图与firebase交谈,但我认为问题在于几乎任何网络连接。有没有已知的排序限制?
有什么想法吗?
更新 - 其余代码
(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);
}
});
}];
}