首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >openweathermap与移动应用程序的问题

openweathermap与移动应用程序的问题
EN

Stack Overflow用户
提问于 2016-03-08 11:51:01
回答 1查看 1.2K关注 0票数 1

我在我的iOS应用程序中使用openweathermap。

下面是我的网址,这是我要求获取的是否信息。

http://api.openweathermap.org/data/2.5/weather?lat=21.282778&lon=-157.829444&APPID=MYAPPID&lang=en-US

当在浏览器中打开这个url时,我得到了正确的响应。

但是当我从我的iOS应用程序调用网络服务时,我没有得到响应。我得到了以下错误:

代码语言:javascript
复制
{
    cod = 401;
    message = "Invalid API key. Please see http://openweathermap.org/faq#error401 for more info.";
}

我从这个网址:在开放式皮革上创建API密钥创建了API键

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-08 12:37:08

代码语言:javascript
复制
NSURL *URL = [NSURL URLWithString:@"http://api.openweathermap.org/data/2.5/weather?q=London,uk&appid=b1b15e88fa797225412429c1c50c122a&lang=en-US"];
    NSURLRequest *request = [NSURLRequest requestWithURL:URL];

    NSURLSession *session = [NSURLSession sharedSession];
    NSURLSessionDataTask *task = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
    {
        NSError* errorObj;
        NSDictionary* json = [NSJSONSerialization
                              JSONObjectWithData:data
                              options:kNilOptions
                              error:&errorObj];

        NSLog(@" response is %@",json);

    }];

    [task resume];

你的应用程序id应该是有效的。我已经为演示用硬编码了url。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35866624

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档