我正在使用 AfNetworking 发出POST请求。在完成块中收到响应后,取消进度调整视图,并在 NSUserDefaults 中保存一些数据。但是当我运行应用程序时,UI不会更新并等待应用程序崩溃以解决内存问题。
这是我的示例代码:
[[HTAPIClient sharedClient] POST:requestAddress
parameters:nil
success:^(NSURLSessionDataTask *task, id responseObject) {
if ([responseObject objectForKey:@"default_source"]) {
NSUserDefaults *usd = [NSUserDefaults standardUserDefaults];
[usd setObject:[responseObject objectForKey:@"default_source"] forKey:@"payViaCreditCard"];
[usd synchronize];
}
NSDictionary *sources = [responseObject objectForKey:@"sources"];
if (sources) {
NSArray *data = [sources objectForKey:@"data"];
if (data) {
// some code
}
}
[self.navigationController popViewControllerAnimated:YES];
[SVProgressHUD dismiss];
}
failure:^(NSURLSessionDataTask *task, NSError *error) {
// some failure
}];
知道如何解决这个问题吗?
感谢您的任何进展!
修改
这就是说XCode到底是什么:
该应用" MyApp" on" iPhone"意外退出。 来自调试器的消息:由于内存错误而终止
答案 0 :(得分:1)
试试这个
NSDictionary *sources = [responseObject objectForKey:@"sources"];
if (sources) {
NSArray *data = [sourcesobjectForKey:@"data"];
if (data) {
// some code
}
}
dispatch_async(dispatch_get_main_queue(), ^{
[SVProgressHUD dismiss];
[self.navigationController popViewControllerAnimated:YES];
});