iOSでネットワーク通信。同期通信版
iPhoneアプリを作っていて、APIからデータを取得するメモ。
同期通信版です。
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. @autoreleasepool { //読み込みの設定 NSString *url = @"data.json"; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; NSURLResponse *response = nil; NSError *error = nil; //データの読み込み NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; }