Created
July 20, 2012 10:32
-
-
Save inonb/3150068 to your computer and use it in GitHub Desktop.
[iOS] URLからデータを取得
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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