Ios 信号机回拨前的UI挂起
我使用信号器发送数据这里是我发送数据的代码Ios 信号机回拨前的UI挂起,ios,objective-c,signalr,signalr-hub,Ios,Objective C,Signalr,Signalr Hub,我使用信号器发送数据这里是我发送数据的代码 manager = [AFHTTPRequestOperationManager manager]; manager.responseSerializer = [AFJSONResponseSerializer serializer]; manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:
manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
setUrl = [NSString stringWithFormat:@"%@%@",[UtilHelper sharedManager].WebServiceURL,@"Save"];
NSDictionary *parameters = [[NSDictionary alloc]initWithObjectsAndKeys:dicArray,@"products", nil];
__block NSMutableArray* json;
json = [[NSMutableArray alloc]init];
[manager POST:setUrl parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSError *writeError = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:responseObject options:NSJSONWritingPrettyPrinted error:&writeError];
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
options:NSJSONReadingMutableContainers
error:&writeError];
if ([[dic valueForKey:@"StatusMsg"] isEqualToString:@"Success"]) {
// save To S3 Bucket
[self sendPicture:[NSString stringWithFormat:@"%@",strProductId] : strPackageId];
[[results objectAtIndex:i] setValue:[NSNumber numberWithBool:YES] forKey:@"productsync"];
[[results objectAtIndex:i] setValue:[NSNumber numberWithBool:YES] forKey:@"editflag"];
[context save:nil];
}
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
现在我在AppDelegate
[hubConnection setReceived:^(NSString *message) {
NSLog(@"%@",message);
});
当setReceived调用my UI hand时,这里是我的代码,我将显示我的UIViewController
,并挂起UI init
-(void)handlePlusOption{
__weak __typeof(&*self)weakSelf = self;
dispatch_async( dispatch_get_main_queue(), ^{
__strong __typeof(&*weakSelf)strongSelf = weakSelf;
strongSelf.addProductVc = [[AddProductVC alloc] initWithNibName:addProductVcIdentifier bundle:nil];
strongSelf.nav = [[UINavigationController alloc] initWithRootViewController:strongSelf.addProductVc];
strongSelf.nav.modalPresentationStyle = UIModalPresentationFormSheet;
strongSelf.nav.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
strongSelf.nav.modalPresentationCapturesStatusBarAppearance = NO; // To hide status bar, doest work with UIModalPresentationPageSheet style
[self.navigationController presentViewController:strongSelf.nav animated:YES completion:NULL];
});
}
为什么UI在setReceived
之前挂起
尝试将setReceived代码块放入此块中
尝试将setReceived代码块放入此块中
我已经尝试过了,在调用setReceived之前,我的UI是挂起的。在下面的主线程中尝试放置setReceived块。这可能会起作用,或者如果您正在发送json数据,您可以使用另一种方法使用sbjson解析器库发送数据。不,还是一样的。我得到了键值作为回应,我的数据并没有那么大,只有6个键值对。这可能是因为发送数据的服务器端吗?@bhadresh我没听懂你的意思..你只是想向只有6个键值对的服务器发送json数据吗?好的,用下面的链接改变你的方法。。我已经尝试过了,在调用setReceived之前,我的UI是挂起的。在下面的主线程中尝试放置setReceived块。这可能会起作用,或者如果您正在发送json数据,您可以使用另一种方法使用sbjson解析器库发送数据。不,还是一样的。我得到了键值作为回应,我的数据并没有那么大,只有6个键值对。这可能是因为发送数据的服务器端吗?@bhadresh我没听懂你的意思..你只是想向只有6个键值对的服务器发送json数据吗?好的,用下面的链接改变你的方法。。
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// time-consuming task
[hubConnection setReceived:^(NSString *message) {
NSLog(@"%@",message);
}];
dispatch_async(dispatch_get_main_queue(), ^{
// run in main thread
});
});