使用cfnetwork写入输出流时的exc_bad_access

时间:2014-01-08 14:48:48

标签: ios objective-c smtp exc-bad-access

我正在开发iPhone应用程序。我试图通过gmail服务器发送带有一个带smtp的URL的消息。我使用CFNetwork框架。有时邮件发送没有问题,但很多时候我在exc_bad_access行获取异常exc_bad_access

(CFWriteStreamCanAcceptBytes(outputStream))

1类:HSK_CFUtilities

CFIndex CFWriteStreamWriteFully(CFWriteStreamRef outputStream, const uint8_t* buffer, CFIndex length)
{
    CFIndex bufferOffset = 0;
    CFIndex bytesWritten;

    while (bufferOffset < length)
    {
        if (CFWriteStreamCanAcceptBytes(outputStream))
        {
            bytesWritten = CFWriteStreamWrite(outputStream, &(buffer[bufferOffset]), length - bufferOffset);
            if (bytesWritten < 0)
            {
                // Bail!                
                return bytesWritten;
            }
            bufferOffset += bytesWritten;
        }
        else if (CFWriteStreamGetStatus(outputStream) == kCFStreamStatusError)
        {
            return -1;
        }
        else
        {
            // Pump the runloop
            CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.0, true);
        }
    }

    return bufferOffset;
}

2类:方法parseBuffer

中的SKPSMTPMessage
 case kSKPSMTPWaitingSendSuccess:
                {
                    if ([tmpLine hasPrefix:@"250 "])
                    {
                        sendState = kSKPSMTPWaitingQuitReply;

                        NSString *quitString = @"QUIT\r\n";
                        DEBUGLOG(@"C: %@", quitString);
                        if (CFWriteStreamWriteFully((CFWriteStreamRef)outputStream, (const uint8_t *)[quitString UTF8String], [quitString lengthOfBytesUsingEncoding:NSUTF8StringEncoding]) < 0)
                        {
                            error =  [outputStream streamError];
                            encounteredError = YES;
                        }
                        else
                        {
                            [self startShortWatchdog];
                        }
                    }

我想知道你是否可以给我一个暗示吗?我将不胜感激任何帮助 。提前谢谢你,最好的问候。

1 个答案:

答案 0 :(得分:4)

因为EXC_BAD_ACCESS错误所以

在我的案例中,我需要strong property所需的.h课程&amp;用过

SKPSMTPMessage对象作为所需类的全局对象,它起作用了。

enter image description here

以下是有关导致EXC_BAD_ACCESS以及如何追踪根问题的重要链接:

Lou Franco's Understanding EXC_BAD_ACCESS