2012-10-24 126 views
0

我正在一個項目,用ttsend照片與smtp。在開始時,自動引用計數被禁用,項目運行沒有問題。當我啓用自動引用計數時,我得到了許多編譯錯誤。其中最常見的是在該線轉換objective-c指針類型nsoutputstream *到c指針類型cfwritestreamref異常後__bridge

if (CFWriteStreamWriteFully((CFWriteStreamRef)outputStream, (const uint8_t *)[ehlo 
UTF8String], [ehlo lengthOfBytesUsingEncoding:NSUTF8StringEncoding]) < 0)      

當我寫 如果鑄造目標C指針類型「NSOutputStream *」的至C指針類型CFWriteStreamRef(又名「struct_CFWriteStream *」需要橋接鑄)(CFWriteStreamWriteFully ((__bridge CFWriteStreamRef)的OutputStream,(常量uint8_t *)
[EHLO UTF8字符串],[EHLO lengthOfBytesUsingEncoding:NSUTF8StringEncoding])< 0)

它編譯,但我得到運行時異常時,我按下發送鍵以發送電子郵件與smtp。我想知道你是否可以幫助我解決這個問題。我將不勝感激任何幫助。在此先感謝您,此致敬意

回答

0

您如何確定它是一個錯誤的類型代碼? 儘量保持所有權[EHLO UTF8字符串]只要流是寫作,也許可以幫助

const UInt8 *buffer = (const UInt8 *)[ehlo UTF8String]; 
if (CFWriteStreamWriteFully((CFWriteStreamRef)outputStream, buffer, [ehlo lengthOfBytesUsingEncoding:NSUTF8StringEncoding]) < 0) 

順便說我還沒有發現那位CFWriteStreamWriteFully()聲明的任何地方。只有CF索引

CFWriteStreamWrite (
    CFWriteStreamRef stream, 
    const UInt8 *buffer, 
    CFIndex bufferLength 
); 

有關聯嗎? UInt8和uint8_t都是無符號字符。

+0

非常感謝您的幫助。但是,我試過了,它沒有奏效。代碼如下: 如果(CFWriteStreamWriteFully((CFWriteStreamRef)的OutputStream, 常量uint8_t *)[EHLO UTF8字符串],[EHLO lengthOfBytesUsingEncoding:NSUTF8StringEncoding])<0){ 錯誤 = [OutputStream的streamError]; encounterError = YES; } else { [self startShortWatchdog]; } –

+0

CFIndex CFWriteStreamWriteFully(CFWriteStreamRef的OutputStream, 常量uint8_t * 緩衝器,CFIndex長度) { CFIndex bufferOffset = 0; CFIndex bytesWritten; 而(bufferOffset <長度) { 如果(CFWriteStreamCanAcceptBytes(OutputStream中)) { bytesWritten = CFWriteStreamWrite(OutputStream中,& (緩衝液[bufferOffset]), - bufferOffset); if(bytesWritten <0) { //保釋! 返回bytesWritten; } –

+0

bufferOffset + = bytesWritten; } else if(CFWriteStreamGetStatus(outputStream) == kCFStreamStatusError) return -1; } else //泵浦runloop CFRunLoopRunInMode(kCFRunLoopDefaultMode,0。0,true); } } return bufferOffset; } [self startShortWatchdog]; } –