【发布时间】:2021-04-05 10:06:12
【问题描述】:
异常生成代码:
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSString* serverURL=getServerUrl();
NSData *postData = [NSJSONSerialization dataWithJSONObject:myPostDataNSArray options:0 error:nil];
[request setHTTPMethod:@"POST"];
[request setURL:[NSURL URLWithString: serverURL]];
[request addValue:@"application/json" forHTTPHeaderField: @"Content-Type"];
[request setHTTPBody:postData];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
堆栈跟踪:
0 libsystem_trace.dylib 0x00007fff7684d8af _os_trace_read_file_at + 417
1 libsystem_trace.dylib 0x00007fff7684d944 _os_trace_read_plist_at + 46
2 libsystem_trace.dylib 0x00007fff7684929b _os_log_preferences_load + 148
3 libsystem_trace.dylib 0x00007fff7684a00a _os_log_preferences_refresh + 110
4 libsystem_trace.dylib 0x00007fff76849bb6 os_log_create + 999
5 libsqlite3.dylib 0x00007fff75e0a834 sqlite3_initialize + 1364
6 libsqlite3.dylib 0x00007fff75e08c02 openDatabase + 114
7 com.apple.CFNetwork 0x00007fff4d5d6fdb -[NSURLCacheDBReader _openDBReadConnections] + 140
8 com.apple.CFNetwork 0x00007fff4d5d6f2b -[NSURLCacheDBReader openAndPrepareReadCacheDB] + 22
9 com.apple.CFNetwork 0x00007fff4d4babd2 __CFURLCache::createNSURLStorageClient(__CFString const*, long, std::__1::shared_ptr<__CFURLCache>) + 166
10 com.apple.CFNetwork 0x00007fff4d5bb052 __CFURLCacheCreateInternal(__CFAllocator const*, long, long, __CFString const*, bool, bool) + 633
11 com.apple.CFNetwork 0x00007fff4d4ba480 -[NSURLCache initWithMemoryCapacity:diskCapacity:diskPath:] + 168
12 com.apple.CFNetwork 0x00007fff4d4ba27b +[NSURLCache sharedURLCache] + 96
13 com.apple.CFNetwork 0x00007fff4d4c7fa8 -[__NSURLSessionLocal _createXURLCache0] + 40
14 com.apple.CFNetwork 0x00007fff4d4c7f34 -[__NSURLSessionLocal _createXURLCache] + 71
15 com.apple.CFNetwork 0x00007fff4d4df282 URLConnectionClient::URLConnectionClient(ClassicURLConnection*, NSURLSessionTask const*, dispatch_queue_s*) + 150
16 com.apple.CFNetwork 0x00007fff4d4df18b URLConnectionClient_Classic::URLConnectionClient_Classic(ClassicURLConnection*, NSURLSessionTask const*, CFURLConnectionClient_V1 const*, dispatch_queue_s*) + 21
17 com.apple.CFNetwork 0x00007fff4d4df02f ClassicURLConnection::initialize(CFURLConnectionClient_V1*, NSURLSessionTask const*) + 145
18 com.apple.CFNetwork 0x00007fff4d4ddecc ClassicURLConnection::initialize(_CFURLRequest const*, _CFURLRequest*, CFURLConnectionClient_V1*, __CFDictionary const*) + 216
19 com.apple.CFNetwork 0x00007fff4d4ddc64 CFURLConnectionCreateWithProperties + 297
20 com.apple.CFNetwork 0x00007fff4d5121cc CFURLConnectionCreate + 52
21 com.apple.CFNetwork 0x00007fff4d5ce4c9 SyncClient::SyncClient(__CFAllocator const*, _CFURLRequest const*, dispatch_queue_s*, void (__CFData const*, _CFURLResponse*, __CFError*) block_pointer) + 213
22 com.apple.CFNetwork 0x00007fff4d5ce1d4 CFURLConnectionSendSynchronousRequest + 326
23 com.apple.CFNetwork 0x00007fff4d5e58a4 +[NSURLConnection sendSynchronousRequest:returningResponse:error:] + 117
我还可以在崩溃日志中看到以下信息:
应用特定信息:
LIBTRACE 客户端中的错误:不要关闭随机 fds
我是目标 c 的新手。提前感谢您的宝贵时间。
【问题讨论】:
-
sendSynchronousRequest在很长一段时间内被弃用(并且不鼓励)。不要使用它。 -
是的,我几天前检查过,我打算用 URLSession 替换它。但我不确定它是否能解决问题。这段代码在很长一段时间内运行良好,我只在一个集成了我的库的应用程序中遇到了这个问题。只是想知道这可能的原因。
标签: objective-c exception nsurlconnection file-descriptor exc-bad-instruction