菜鸟教程小白 发表于 2022-12-13 05:55:21

ios - 使用 cfnetwork 写入输出流时的 exc_bad_access


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

<pre><code>(CFWriteStreamCanAcceptBytes(outputStream))
</code></pre>

<p>1 类:HSK_CFUtilities</p>

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

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

    return bufferOffset;
}
</code></pre>

<p>2 类:方法 <code>parseBuffer</code></p> 中的 SKPSMTPMessage

<pre><code> case kSKPSMTPWaitingSendSuccess:
                {
                  if ()
                  {
                        sendState = kSKPSMTPWaitingQuitReply;

                        NSString *quitString = @&#34;QUIT\r\n&#34;;
                        DEBUGLOG(@&#34;C: %@&#34;, quitString);
                        if (CFWriteStreamWriteFully((CFWriteStreamRef)outputStream, (const uint8_t *), ) &lt; 0)
                        {
                            error =;
                            encounteredError = YES;
                        }
                        else
                        {
                            ;
                        }
                  }
</code></pre>

<p>我想知道你是否可以给我一个提示?我将不胜感激任何帮助 。提前谢谢你,最好的问候。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>因为是<code>EXC_BAD_ACCESS</code>错误所以</p>

<p>在我的情况下,当我在需要的 .h 类中制作 <code>SKPSMTPMessage</code> 的 <code>strong</code> <code>property</code> 并使用时</p>

<p><code>SKPSMTPMessage</code> 对象作为所需类的全局对象,它起作用了。 </p>

<p> <img src="/image/55Gkh.png" alt="enter image description here"/> </p>

<p>这里有一个很好的链接,说明了导致 EXC_BAD_ACCESS 的原因以及如何追查根本问题:</p>

<p> <a href="http://loufranco.com/blog/understanding-exc_bad_access" rel="noreferrer noopener nofollow">Lou Franco&#39;s Understanding EXC_BAD_ACCESS</a> </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 使用 cfnetwork 写入输出流时的 exc_bad_access,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/20998850/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/20998850/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 使用 cfnetwork 写入输出流时的 exc_bad_access