Skip to content

Instantly share code, notes, and snippets.

@inonb
Created July 20, 2012 10:32
Show Gist options
  • Save inonb/3150068 to your computer and use it in GitHub Desktop.
Save inonb/3150068 to your computer and use it in GitHub Desktop.
[iOS] URLからデータを取得
- (void)getURL
{
// URLクラスを作る
NSURL *url = [NSURL URLWithString:@"http://apple.com"];
// リクエストを作る
NSURLRequest *request = [NSURLRequest requestWithURL:url];
// 接続してデータを取得
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
// 取得したデータがコールバックブロックに返る
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
// 結果をログに出力
NSLog(@"%@", responseString);
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment