iOS 14 个无法识别的选择器发送到 IoTHubClient_LL_DoWork() 上的实例异常

iOS 14 unrecognized selector sent to instance exception on IoTHubClient_LL_DoWork()

更新到 iOS 14 后,每当它在代码中命中 IoTHubClient_LL_DoWork() 时都会导致一致崩溃。

日志:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString objectForKey:]: unrecognized selector sent to instance 0x7fff801abf28'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff20438fda __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007fff2017712e objc_exception_throw + 48
2 CoreFoundation 0x00007fff20447b29 +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
3 CoreFoundation 0x00007fff2043d510 forwarding + 1479
4 CoreFoundation 0x00007fff2043f548 _CF_forwarding_prep_0 + 120
5 CFNetwork 0x00007fff235bfa29 _CFStreamErrorFromCFError + 216339
6 CFNetwork 0x00007fff235b67cd _CFStreamErrorFromCFError + 178871
7 CoreFoundation 0x00007fff203c88bf CFReadStreamSetProperty + 93
8 AzureIoTUtility 0x000000010da5a848 dowork_poll_socket + 136
9 AzureIoTUtility 0x000000010da5a183 tlsio_appleios_dowork + 179
10 AzureIoTUtility 0x000000010da66f04 xio_dowork + 52
11 AzureIoTuMqtt 0x000000010db1f0c3 mqtt_client_dowork + 115
12 AzureIoTHubClient 0x000000010d99de7e IoTHubTransport_MQTT_Common_DoWork + 1038
13 AzureIoTHubClient 0x000000010d9ae905 IoTHubTransportMqtt_DoWork + 21
14 AzureIoTHubClient 0x000000010d96e581 IoTHubClientCore_LL_DoWork + 337
15 AzureIoTHubClient 0x000000010d972da5 IoTHubClient_LL_DoWork + 21
16 Locate2u 0x000000010cf58b31 $s8Locate2u22ServerMessagingServiceC6doworkyyF + 33
17 Locate2u 0x000000010cf58b6b $s8Locate2u22ServerMessagingServiceC6doworkyyFTo + 43
18 Foundation 0x00007fff2086e90c __NSFireTimer + 67
19 CoreFoundation 0x00007fff203a7ed4 CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION + 20
20 CoreFoundation 0x00007fff203a79a7 __CFRunLoopDoTimer + 926
21 CoreFoundation 0x00007fff203a6f5a __CFRunLoopDoTimers + 265
22 CoreFoundation 0x00007fff203a15e8 __CFRunLoopRun + 1949
23 CoreFoundation 0x00007fff203a0960 CFRunLoopRunSpecific + 567
24 GraphicsServices 0x00007fff2b9e7db3 GSEventRunModal + 139
25 UIKitCore 0x00007fff245f5bd9 -[UIApplication _run] + 912
26 UIKitCore 0x00007fff245faaea UIApplicationMain + 101
27 Locate2u 0x000000010cf7f21b main + 75
28 libdyld.dylib 0x00007fff20256431 start + 1
29 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString objectForKey:]: unrecognized selector sent to instance 0x7fff801abf28'
terminating with uncaught exception of type NSException
CoreSimulator 732.10 - Device: iPhone 11 Pro 14 (81C14598-2ABC-4BF2-9064-51EF9C9A31B0) - Runtime: iOS 14.0 (18A5342e) - DeviceType: iPhone 11 Pro
This process is running with libgmalloc.dylib (GuardMalloc) which may have forced the crash due to a memory access error.

在此处添加答案以供参考 Git 问题链接:

它需要一本字典。替换以下代码

static void dowork_poll_socket(TLS_IO_INSTANCE* tls_io_instance)
{
// This will pretty much only fail if we run out of memory

CFStreamCreatePairWithSocketToHost(NULL, tls_io_instance->hostname, tls_io_instance->port, &tls_io_instance->sockRead, &tls_io_instance->sockWrite);

if (tls_io_instance->sockRead != NULL && tls_io_instance->sockWrite != NULL)
{
    
    // Micha Edits
    
    CFStringRef keys[1] = {kCFStreamPropertySocketSecurityLevel};
    CFStringRef values[1] = {kCFStreamSocketSecurityLevelNegotiatedSSL};

    CFDictionaryRef test = CFDictionaryCreate(NULL , (void *)keys , (void *)values , 1,  NULL , NULL);
    
    if (CFReadStreamSetProperty(tls_io_instance->sockRead, kCFStreamPropertySSLSettings, test))

    //if (CFReadStreamSetProperty(tls_io_instance->sockRead, kCFStreamPropertySSLSettings, kCFStreamSocketSecurityLevelNegotiatedSSL))
    {
        tls_io_instance->tlsio_state = TLSIO_STATE_OPENING_WAITING_SSL;
    }
    else
    {
        LogError("Failed to set socket properties");
        enter_open_error_state(tls_io_instance);
    }
    
    CFRelease(test);
}
else
{
    LogError("Unable to create socket pair");
    enter_open_error_state(tls_io_instance);
}
}

此外,IoTHubClient 的最新 CocoaPod 是:pod 'AzureIoTHubClient','=1.3.9-LTS'。尽管 cocoapods 网站较新,但它可能没有指向它。每当我们发布新的 pods 时,您都可以在 this Podfile.

中找到最新的引用