0
날씨가 많은 API를 사용하는 날씨 앱을 작성하려고합니다. apiKey가 있는데 아래 코드에서 사용했지만 ' 디버그 영역에서 어떤 결과가 보이지 않습니다 ... Xcode가 "EXPRESSION RESULT UNUSED"행에 경고를 표시합니다. ... 문제입니까? 아무도 나를 도와 줄 수 있습니까?Weather Underground 서비스에서 XML 파일을받을 수 없습니다.
#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
그리고
#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
나는 인터넷을 해제하려고하면
연결 디버그 영역에서 "오류 메시지"를 볼 수 있지만 인터넷 연결을 켜면 활동 표시기가 영원히 회전하는 것을 볼 수 있습니다 ...답변 해 주셔서 감사합니다 .... 나는 잃어버린 느낌이 ...