我已发出 api 请求以从我的后端服务获取一些详细信息:
我想关闭我当前的 View Controller 并通过来自后端的 url 启动一个新网页:
NSDictionary *parameters = @{@"X-Service-Code" : @"PP", @"Accept" : @"application/json", @"Content-Type" : @"application/json"};
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager GET:url1 parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSMutableArray *jsonArray = [[NSMutableArray alloc]init];
jsonArray = [NSJSONSerialization JSONObjectWithData: responseObject options:NSJSONReadingMutableContainers error:nil];
[self dismissViewControllerAnimated:YES completion:nil];
NSString *urlAddress = [[jsonArray objectAtIndex:10]valueForKey:@"value"];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlAddress]]];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
Web View 正在后台启动,但 View Controller 并未被关闭。有什么建议吗?
最佳答案
dismissViewControllerAnimated
需要在主线程上调用:
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:YES completion:nil];
});
关于ios - 关闭应用程序并在 appstart 上启动 webview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44487905/