Iphone 我能';t从气象地下服务处接收XML文件

Iphone 我能';t从气象地下服务处接收XML文件,iphone,ios,xml,api,Iphone,Ios,Xml,Api,我正在尝试编写一个天气应用程序,使用WundergroundAPI。。。 我有一个apiKey,我在下面的代码中使用了它,但在调试区域我看不到任何结果。。。 Xcode在“表达式结果未使用”一行中显示警告…这就是问题所在吗? 有人能帮我吗 #import "WeatherForecast.h" #import "MainViewController.h" @implementation WeatherForecast - (void) queryServiceWithState:(NSStr

我正在尝试编写一个天气应用程序,使用WundergroundAPI。。。 我有一个apiKey,我在下面的代码中使用了它,但在调试区域我看不到任何结果。。。 Xcode在“表达式结果未使用”一行中显示警告…这就是问题所在吗? 有人能帮我吗

#import "WeatherForecast.h"
#import "MainViewController.h"

@implementation WeatherForecast

- (void) queryServiceWithState:(NSString *)state
                andCity:(NSString *)city
                withParent:(UIViewController *)controller {
viewController = (MainViewController *)controller;
responseData = [NSMutableData data];
apiKey = @"c5f79118382c6e91";

NSString *url =
[NSString stringWithFormat:
 @"http://api.wunderground.com/api/%@/conditions/q/%@//%@.xml",
 apiKey, state, city];

theURL = [NSURL URLWithString:url];
NSURLRequest *request = [NSURLRequest requestWithURL:theURL];
[[NSURLConnection alloc] initWithRequest:request delegate:self];//EXPRESSION RESULT     UNUSED
}


#pragma mark NSURLConnection Delegate Methods

- (NSURLRequest *)connection:(NSURLConnection *)connection
         willSendRequest:(NSURLRequest *)request
        redirectResponse:(NSURLResponse *)response{
@autoreleasepool {
    theURL = [request URL];
}
return request;
}

- (void)connection:(NSURLConnection *)connection
didReceiveResponse:(NSURLResponse *)response {
[responseData setLength:0];
}


-(void)connection:(NSURLConnection *)connection
didReceiveData:(NSData *)data {
[responseData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"Error = %@",error);
}

- (void)connectionDidFinishiLoading: (NSURLConnection *)connection {
NSString *content =
[[NSString alloc]initWithBytes:[responseData bytes]
                        length:[responseData length]
                      encoding:NSUTF8StringEncoding];
NSLog ( @"Data = %@",content);

//...Insert code to parse the content here...

[viewController updateView];

}

@end
我的应用程序还有一个2.m文件,可能是其中一个错误

#import "MainViewController.h"
#import "WeatherForecast.h"

@interface MainViewController ()

@end

@implementation MainViewController

- (void)viewDidLoad
{
 [super viewDidLoad];
[self refreshView:self];
}

- (IBAction)refreshView:(id)sender {
 [loadingActivityIndicator startAnimating];
 [self.forecast queryServiceWithState:@"UK" andCity:@"London" withParent:self];
}


- (void)updateView {

//...

[loadingActivityIndicator stopAnimating];
} 

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

#pragma mark - Flipside View

- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
{
[self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)showInfo:(id)sender
{    
FlipsideViewController *controller = [[FlipsideViewController alloc]               

initWithNibName:@"FlipsideViewController" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:controller animated:YES completion:nil];
}

@end

如果我尝试关闭internet连接,我可以在调试区域中看到“错误消息”,但是如果我打开internet连接,那么我只能看到活动指示器永远旋转


感谢您的回复…我感到很失落…

您得到的
表达式结果未使用的
是连接对象。您通常应该将其存储到属性中,以确保在您仍在使用时不会将其销毁

#import "AppDelegate.h"
#import "WeatherForecast.h"
#import "MainViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    

(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.mainViewController = [[MainViewController alloc]     

initWithNibName:@"MainViewController" bundle:nil];

WeatherForecast *forecast = [[WeatherForecast alloc] init];
self.mainViewController.forecast = forecast;


self.window.rootViewController = self.mainViewController;
[self.window makeKeyAndVisible];
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{

}

- (void)applicationDidEnterBackground:(UIApplication *)application
{

}

- (void)applicationWillEnterForeground:(UIApplication *)application
{

}

- (void)applicationDidBecomeActive:(UIApplication *)application
{

}

- (void)applicationWillTerminate:(UIApplication *)application
{

}

@end