ねえ、私はこのようなIOSのURLからデータを取得する方法
NSString *urlString = @" http://api.openweathermap.org/data/2.5/forecast/daily?q=Indore&mode=json&units=metric&cnt=10&APPID=fc632e2569dbdbb07ca79e239faa0281";
ねえ、私はこのようなIOSのURLからデータを取得する方法
NSString *urlString = @" http://api.openweathermap.org/data/2.5/forecast/daily?q=Indore&mode=json&units=metric&cnt=10&APPID=fc632e2569dbdbb07ca79e239faa0281";
//Init the NSURLSession with a configuration
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]];
//Create an URLRequest
NSURL *url = [NSURL URLWithString:@"yourURL"];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
//Create POST Params and add it to HTTPBody
NSString *params = @"api_key=APIKEY&[email protected]&password=password";
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]];
//Create task
NSURLSessionDataTask *dataTask = [defaultSession dataTaskWithRequest:urlRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
//Handle your response here
}];
[dataTask resume];
与えられたURLを取得してください... –
編集中!ちょうど辞書を使用する! –
'sendSynchronousRequest'はiOS 9では廃止されました。実際には、' NSURLSession'で置き換えられたので、 'NSURLConnection'を使用しないでください。 – pajevic
使用NSUrlSession
...このURLからデータをフェッチして助けてくださいIOSの新たなんだ:
NSString *urlString = @"http://api.openweathermap.org/data/2.5/forecast/daily?q=Indore&mode=json&units=metric&cnt=10&APPID=fc632e2569dbdbb07ca79e239faa0281";
NSURLSession *session = [NSURLSession sharedSession];
[[session dataTaskWithURL:[NSURL URLWithString:urlString] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
// handle the response
}] resume];
https://www.raywenderlich.com/110458/nsurlsession-tutorial-getting-started –
これを取得できますか。たとえば –
これはあなたが探しているものです:https://github.com/skdevil/WeatherApp このプロジェクト用にPODをインストールする知識が必要です。 –