0

I am running into an issue. Same code running OK on iPhone (iOS 5) and iPhone/iPad simulator. But it does not work on an iPad (iOS 5). I'd appreciate any help.

Here is read port code:

//Code for read port.
 CFIndex bytesRead = CFReadStreamRead(inputStream, bufferPoint, 1024);
 if (bytesRead < 0) {
     NSLog(@"bytesRead < 0");
     CFErrorRef error = CFReadStreamCopyError(inputStream);
     //reportError(error);
     DEBUGLOG(@"readResponse error \n")

Before above, there is connection part code.

//prevent to release before relocate
if ((inputStream != nil) && (outputStream != nil)) {
    [inputStream release];
    inputStream = nil;
    [outputStream release];
    outputStream = nil;
}
[NSStream getStreamsToHostNamed:relayHost port:relayPort inputStream:&inputStream outputStream:&outputStream];
//[self lgetStreamsToHostNamed:relayHost port:relayPort inputStream:&inputStream outputStream:&outputStream];
if ((inputStream != nil) && (outputStream != nil))
{
    sendState = kIMAPConnecting;

    isSecure = NO;

    [inputStream retain];
    [outputStream retain];

    [inputStream setDelegate:self];
    [outputStream setDelegate:self];


    result = [inputStream setProperty:NSStreamSocketSecurityLevelNegotiatedSSL forKey:NSStreamSocketSecurityLevelKey];
    DEBUGLOG(@"inputStream setProperty result: %d", result);
    result =[ outputStream setProperty:NSStreamSocketSecurityLevelNegotiatedSSL forKey:NSStreamSocketSecurityLevelKey];
    DEBUGLOG(@"outputStream setProperty result: %d", result);


    if (!CFReadStreamOpen(inputStream)) {
        DEBUGLOG(@"inputStream open failed");
        return NO;
    }

    if (!CFWriteStreamOpen(outputStream)) {
        DEBUGLOG(@"outputStream open failed");
        return NO;
    }



    self.inputString = [NSMutableString string];        

    DEBUGLOG(@"SCRIMAPMessage startToConnect end with YES\n");
    return YES;
}
SetFreeByTruth
  • 819
  • 8
  • 23
user459014
  • 21
  • 3

1 Answers1

0

The following is not available via iOS:

[NSStream getStreamsToHostNamed:relayHost port:relayPort inputStream:&inputStream outputStream:&outputStream];

I really do not know how it can work on iOS for the iPhone.

Your options are fairly simple...

A) Create a category on NSStream as described in this technical note from Apple: here

B) Use CFStreamCreatePairWithSocketToHost() and simply bridge CFReadStreamRef/CFWriteStreamRef

I recommend (B) as it will give you the best option for flexibility. More specifically you can create your own StreamObject class to handle this and the stream delegate all in one.

Happy coding!

Arvin
  • 2,516
  • 27
  • 30