首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xcode天气应用

Xcode天气应用
EN

Stack Overflow用户
提问于 2011-04-29 00:51:38
回答 2查看 8K关注 0票数 3

我想试着做一个天气预报应用。但我如何获取天气信息并在我的应用程序中使用它们?

我听说过Google IPA,但是怎么用呢?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-04-29 01:54:08

首先选择最适合您的天气应用编程接口:https://stackoverflow.com/questions/507441/best-weather-apis

包括Google在内的大多数API都以XML格式返回结果。

快速编写示例代码,帮助您开始使用Google Weather API:

代码语言:javascript
复制
NSString * location =  @"Amsterdam";
NSString * address = @"http://www.google.co.uk/ig/api?weather=";
NSString * request = [NSString stringWithFormat:@"%@%@",address,location];
NSURL * URL = [NSURL URLWithString:request];
NSError * error;    
NSString* XML = [NSString stringWithContentsOfURL:URL encoding:NSASCIIStringEncoding error:&error];

// Extract current temperature the 'dirty' way
NSString * temp = [[[[XML componentsSeparatedByString:@"temp_c data=\""] objectAtIndex:1] componentsSeparatedByString:@"\""] objectAtIndex:0];
NSLog(@"It's currently %@ degree in %@.", temp, location);

// Parse the XML with NSXMLDocument to extract the data properly
NSXMLDocument * doc = [[NSXMLDocument alloc] initWithXMLString:XML options:0 error:NULL];

输出:

阿姆斯特丹的气温目前是华氏14度。

票数 9
EN

Stack Overflow用户

发布于 2018-11-15 15:08:21

我使用- Swift,面向协议的编程(POP),可编码的,MVVM,OpenWeatherMap设计模式和单元测试创建了示例iOS天气应用程序

https://github.com/deepakiosdev/WeatherApp/tree/master

也许这会对那些正在寻找所有这些东西的人有所帮助。

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

https://stackoverflow.com/questions/5822186

复制
相关文章

相似问题

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