【发布时间】:2017-06-28 09:57:28
【问题描述】:
运行以下代码时,我在 Xcode 控制台上遇到错误:
// Create session
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration]];
// Create request
NSURL *url = [NSURL URLWithString:@"https://my.backend.com/endpoint"];
NSMutableURLRequest *mutableRequest = [NSMutableURLRequest requestWithURL:url];
mutableRequest.HTTPMethod = @"POST";
[mutableRequest setValue:@"text/plain" forHTTPHeaderField:@"Content-Type"];
NSData *postBody = [@"my_string_payload" dataUsingEncoding:NSUTF8StringEncoding];
[mutableRequest setHTTPBody:postBody];
// Create and initiate task
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:mutableRequest];
[dataTask resume];
我得到的错误如下:
... [Common] _BSMachError: port c11b; (os/kern) invalid capability (0x14) "Unable to insert COPY_SEND"
... [Common] _BSMachError: port c11b; (os/kern) invalid name (0xf) "Unable to deallocate send right"
运行resume 方法时显示错误。一切似乎都正常,没有崩溃,请求按预期工作。
我已查找此错误消息,通常发现它与 1) 奇怪的 Xcode 问题(例如 this)或 2) UI 元素生命周期(例如 here)有关。不过,这些似乎不适用于本案。
我使用的是 Xcode 8.3.3。
【问题讨论】:
-
只是出于兴趣,你为什么不使用 NSURLSession 块?
-
@Supertecnoboff 你的意思是 NSURLSessionDataTask 的完成处理程序吗?在实际代码中,我正在使用它,但为了这个问题,我将示例缩小到一个仍然存在问题的更简单的版本。
标签: ios objective-c xcode nsurlsession