title: How to use NSStream load a network url?
body: <p>I tried to load a web MP3 link with inputStreamWithURL: API, but every time I got _inputStream nil, _inputStream wasn't nil when I changed the URL to a local link. But I've looked up a lot of information that says you can use this API to load web links.
  <a href="https://i.stack.imgur.com/4Atx3.png" rel="nofollow noreferrer">Code</a></p>
  <pre><code>- (void)setupConfig:(NSString *)urlstr {
      NSURL *url=[NSURL URLWithString:urlstr];
      NSString *path = [NSHomeDirectory() stringByAppendingString:@&quot;/tmp/douas-f22c23979d42e54226ae74a70c411961569809dc302d92e2c63a4894f0e9aaca.tmp&quot;];
      BOOL isexist = [NSFileManager.defaultManager fileExistsAtPath:path];
  //    _inputStream = [[NSInputStream alloc] initWithFileAtPath:path];
  //    _inputStream = [NSInputStream.alloc initWithURL:url];
      
      _inputStream = [NSInputStream inputStreamWithURL:url];
      [_inputStream setDelegate:self];
      
      [NSThread detachNewThreadSelector:@selector(threadMethods) toTarget:self withObject:nil];
  }
  -(void)scheduleStream {
      [_inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
      [_inputStream open];
  }
  -(void)threadMethods {
      @autoreleasepool {
          [self scheduleStream];
          [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:20.0]];
      }
  }
  </code></pre>