dispatch_sync(dispatch_get_main_queue(), ^{ [self dismissLoginWindow]; });注意,dispatch_suspend (以及dispatch_resume)在主线程上不起作用。
- (void)getAaaaMainInfo
{
dispatch_block_t block = ^{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *url=[NSString stringWithFormat:@"%@/interface/aaaa.php", severAddress];
ASIFormDataRequest*request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:url]];
//NSString *_JSon=[dict JSONRepresentation];
[request setTimeOutSeconds:REQUEST_TIME_OUT_SEC];
[request setRequestMethod:@"POST"];
NSMutableData *body = [NSMutableData data];
//[body appendData:[_JSon dataUsingEncoding:NSUTF8StringEncoding]];
[request appendPostData:body];
[request startSynchronous];
//解析返回字段
NSString *responseStr = [request responseString];
NSString *retCode = @"0";//1 表示请求成功 其它则失败
//请求有还回
NSArray *postResult = [responseStr JSONValue];
NSMutableArray *resultAry = nil;
if ([responseStr length] > 0 && postResult) {
retCode = @"1";
resultAry = [NSMutableArray arrayWithCapacity:2];
for (NSDictionary *dict in postResult) {
NSMutableDictionary *temDic = [[NSMutableDictionary alloc] initWithDictionary:dict];
[resultAry addObject:temDic];
[temDic release];
}
}
//进入主线程里操作
dispatch_async(dispatch_get_main_queue(), ^{
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:3];
[dict setObject:retCode forKey:@"returnCode"];
if ([retCode isEqualToString:@"1"]) {
[dict setObject:resultAry forKey:@"returnInfo"];
}
[[NSNotificationCenter defaultCenter] postNotificationName:RESPONSE_GET_ACTIVE_INFO
object:nil
userInfo:dict];
});
[pool drain];
};
dispatch_async(requestQueue, block);
}