简体   繁体   English

从XML获取空值,但仅在仅Wi-Fi设备上

[英]Getting null back from XML, but only on wi-fi only devices

I have an app that incorporates weather...data that I receive from Google's weather API. 我有一个应用程序,其中包含从Google的天气API中接收到的天气...数据。 I'm busting my brain trying to figure out a problem that I'm having and I've been unsuccessful so I figured it was time to ask around on here. 我正在用脑筋试图找出我遇到的问题,但是我一直没有成功,所以我认为是时候在这里问问题了。

Here is my code: 这是我的代码:

query = [[NSString stringWithFormat:@"%@",query] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"query: %@",query);

// SET GOOGLE WEATHER XML LOCATION
CXMLDocument *parse = [[CXMLDocument alloc]initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.google.com/ig/api?weather=%@", query]]options:0 error:nil];
NSLog(@"URL: %@", parse);

The query variable holds my reverse geocoder location (eg Chicago,IL) for which I append it to the Google URL to get the XML back. 查询变量保存了我的反向地址解析器位置(例如,伊利诺伊州芝加哥),为此我将其附加到Google URL上以获取XML。

As you can see I'm logging out both the query and the parse variables. 如您所见,我正在注销查询和解析变量。 I can see that I'm getting a legit query location for my current location when the code is executed, but by the time I log the parse variable I get nothing. 我看到执行代码后,我得到的是我当前位置的合法查询位置,但是当我登录parse变量时,我什么也没得到。 The parse logging shows null...nothing was returned from Google. 解析记录显示为null ... Google没有返回任何信息。 I can see that the URL is correct and I can even go to my browser and get the data I need by using the same logged link. 我可以看到该URL是正确的,甚至可以使用相同的日志链接转到浏览器并获取所需的数据。

Interestingly enough...it works perfectly in the simulator and it also works just fine on my iPhone running 5.1.1. 有趣的是...它在模拟器中完美运行,在运行5.1.1的iPhone上也可以正常运行。 I do have iOS6b4 installed on my iPad which is giving the issue, but since I'm not using any new code that was introduced in iOS6 it shouldn't cause any issues here. 我确实在iPad上安装了iOS6b4,这可以解决此问题,但是由于我没有使用iOS6中引入的任何新代码,因此在这里不会造成任何问题。

Any ideas as to why the XML parsing refuses to work on a wi-fi only iPad? 关于XML解析为什么拒绝在仅支持Wi-Fi的iPad上运行的任何想法?

BTW, before anyone tells me to start using NSXMLParser instead of TouchXML...I do have a test version that runs NSXMLParser instead and I'm getting the same issue there as well. 顺便说一句,在任何人告诉我开始使用NSXMLParser而不是TouchXML之前……我确实有一个测试版本运行NSXMLParser,我在那里也遇到了同样的问题。 I'm at a loss. 我很茫然。

I finally figured this out...it actually had to do with the locationManager. 我终于弄清楚了……实际上与locationManager有关。

I had the following code: 我有以下代码:

 if ([locationManager respondsToSelector:@selector(startMonitoringSignificantLocationChanges)]) {
    [locationManager startMonitoringSignificantLocationChanges]; }
 else {
     [locationManager startUpdatingLocation]; }

Getting rid of the if/else statement and just going with the following resolved it: 摆脱if / else语句,仅执行以下操作即可解决该问题:

[locationManager startUpdatingLocation];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM