2009-11-24 17 views
0

好的,這裏沒什麼特別的,沒有錯誤,我確實聲明NSMutableData *receivedData; 但我返回<>當我期望返回一個網頁時;這是怎麼回事?簡單的NSURL出來蘋果文檔不工作?

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com"] 
              cachePolicy:NSURLRequestUseProtocolCachePolicy 
              timeoutInterval:60.0]; 

    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 

    if (theConnection) { 
      receivedData = [[NSMutableData data] retain]; 
      NSLog(@"receivedData %@", receivedData); 
    } else { 
      // inform the user that the download could not be made 
    } 
} 

回答

2

你似乎指的是URL Loading System「使用NSURLConnection的」節......但它看起來像你停止複製的代碼示例後直接讀取。閱讀下一節。你只有創建數據對象'捕捉'傳入的數據。實際處理響應並將其放置在數據對象中需要更多的代碼。毫不奇怪,後來立即登錄什麼都沒有。

+0

是的,天哪我覺得啞巴。添加代表,最後我會吐出一堆字節,假設只需要將它們轉換爲可讀的文本。 – 2009-11-24 19:22:35