Search code examples
objective-cxcodeios16

iOS16 Enqueued from GCDAsyncSocket


I updated xcode14 and ran my code on an ios16 phone and it crashed. All mobile apps under ios16 are working normally。 The system prompts for the following message,

{
    LogTrace();
    
    NSAssert(dispatch_get_specific(IsOnSocketQueueOrTargetQueueKey), @"Must be dispatched on socketQueue");
    NSAssert((readStream != NULL && writeStream != NULL), @"Read/Write stream is null");
    
    CFStreamStatus readStatus = CFReadStreamGetStatus(readStream);
    CFStreamStatus writeStatus = CFWriteStreamGetStatus(writeStream);
    
    if ((readStatus == kCFStreamStatusNotOpen) || (writeStatus == kCFStreamStatusNotOpen))
    {
        LogVerbose(@"Opening read and write stream...");
        
        BOOL r1 = CFReadStreamOpen(readStream);//Enqueued from GCDAsyncSocket (Thread 7)
        BOOL r2 = CFWriteStreamOpen(writeStream);
        
        if (!r1 || !r2)
        {
            LogError(@"Error in CFStreamOpen");
            return NO;
        }
    }
    
    return YES;
}

Error message:

Enqueued from GCDAsyncSocket (Thread 7)

which is what I did when I called the xmpp connection. I tried to find the problem, but I couldn't figure it out.


Solution

  • CocoaAsyncSocket library is using Background sockets which is not the apple's recommended way. Library itself deprecated the property since iOS 10 (from 2016). And the library also recommends to use "PushKit and the XEP-0357 module" instead of this.

    Set enableBackgroundingOnSocket to false to resolve this issue.

    asyncSocket.enableBackgroundingOnSocket = NO;