Is there anything like 'getStreamsToHost' on real iPhone device?

I want to write an NSOutputStream to a server with apple’s sample code:


NSURL *website = [NSURL URLWithString:str_IP];
NSHost *host = [NSHost hostWithName:[website host]];
[NSStream getStreamsToHost:host port:1100 inputStream:nil outputStream:&oStream];
[oStream retain];
[oStream setDelegate:self];
[oStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[oStream open];

These codes works well on the iPhone simulator, but when I build it to real device. Two warnings pop up. The problem is:

  • How Can I get Mime Type in IOS which is not based on extension
  • using livu (lib) with phonegap?
  • Reading an InputStream into a Data object
  • My AVPlayer should not resume from last point for LIVE Streaming
  • How to buffer audio using AVPlayer in iOS?
  • How to play video stream with MPMoviePlayerController in iOS
  • 1)class NSHost doesn’t belong to iphone os library

    2)getStreamsToHost is not found either

    Any suggestions for the alternative method or class which can be used on real device?

    Solutions Collect From Internet About “Is there anything like 'getStreamsToHost' on real iPhone device?”

    Since CFWriteStream is toll-free bridged to NSOutputStream you can use CFStreamCreatePairWithSocketToHost to get your stream pair:

    CFReadStreamRef readStream = NULL;
    CFWriteStreamRef writeStream = NULL;
    CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (CFStringRef)host, port, &readStream, &writeStream);
    if (readStream && writeStream) {
        CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
        CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
    
        inputStream = (NSInputStream *)readStream;
        [inputStream retain];
        [inputStream setDelegate:self];
        [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
        [inputStream open];
    
        outputStream = (NSOutputStream *)writeStream;
        [outputStream retain];
        [outputStream setDelegate:self];
        [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
        [outputStream open];
    }
    
    if (readStream)
        CFRelease(readStream);
    
    if (writeStream)
        CFRelease(writeStream);