同一线程加锁是没有效果的,多线程加锁才能起作用
dispatch_async(dispatch_get_global_queue(0, 0), ^{
@synchronized (kFeedBackLock) {
if ([bodyDict containsObjectForKey:@"conversineType"] && [bodyDict containsObjectForKey:@"ackId"]) {
NSInteger type = [bodyDict[@"conversineType"] integerValue];
// NSUserDefaults 线程安全 保存信息, 每隔30s向后台发送回执
if (type == NFConversineTypePrivite) { // 私聊
[self saveFeedBackListWithBodyDict:bodyDict chatKey:kSingleChatKey];
} else if (type == NFConversineTypeGroup) { // 群聊
[self saveFeedBackListWithBodyDict:bodyDict chatKey:kGroupChatKey];
} else if (type == NFConversineTypeSystem) { // 系统消息
NSLog(@"信息:线程: %@", [NSThread currentThread]);
NSLog(@"信息:bodyDict: %@", bodyDict);
[self saveFeedBackListWithBodyDict:bodyDict chatKey:kSystemChatKey];
}
}
}
});
网友评论