0
我有這樣的代碼從Objective-C發送消息並獲取返回值?
NSString *tr = [self sendUrl:@"http://google.com/"];
但出於某種原因「TR」仍將執行完成後爲零。我究竟做錯了什麼?
sendUrl:
- (NSString *)sendUrl:(NSString *) uri {
NSLog(@"Requesting URI 1 ...");
// Prepare URL request to download statuses from Twitter
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:uri]];
NSLog(@"Requesting URI 2 ...");
// Perform request and get JSON back as a NSData object
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSLog(@"Requesting URI 3 ...");
// Get JSON as a NSString from NSData response
NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
NSLog(@"Requesting URI 4 ...");
return json_string;
}
sendUrl的實現是什麼:? – BoltClock 2010-05-22 15:30:25
看起來很好。你是否100%確定你的sendUrl函數正在工作 - 分步執行代碼並向你自己證明。 – blissapp 2010-05-22 15:30:25
sendUrl不是內置方法,是不是?我無法搜索它?你可以給我鏈接到方法描述/文檔。沒有這些,我不知道會發生什麼 – vodkhang 2010-05-22 15:31:32