【问题标题】:_BSMachError with NSURLSessionDataTask_BSMachError 与 NSURLSessionDataTask
【发布时间】: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


【解决方案1】:

我刚刚意识到只有在使用断点运行时才会出现错误。当我在没有断点的情况下运行此部分时,请求仍然按预期工作,并且控制台中没有错误,因此看起来这只是在使用断点调试 NSURLSessionDataTask 时出现的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-03
    • 1970-01-01
    • 2017-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多