2012-02-16 5 views
0

'stringWithContentsOfURL'と書くと、 'stringWithContentsOfURLが廃止されました'というエラーが表示されます。ios5でこのステートメントを置き換える方法

-(CLLocationCoordinate2D) addressLocation 
{ 
     NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", 
     [addressField.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 
     NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]]; 
     NSArray *listItems = [locationString componentsSeparatedByString:@","]; 

     double latitude = 0.0; 
     double longitude = 0.0; 

     if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) { 
      latitude = [[listItems objectAtIndex:2] doubleValue]; 
      longitude = [[listItems objectAtIndex:3] doubleValue]; 
     } 
     else { 
      //Show error 
     } 
     CLLocationCoordinate2D location; 
     location.latitude = latitude; 
     location.longitude = longitude; 

     return location; 
    } 

この行をどのように置き換えることができますか。ありがとう!

NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]]; 
+0

は、return文の直後。 – hotpaw2

答えて

1

それは

stringWithContentsOfURL:encoding:error: 

または

stringWithContentsOfURL:usedEncoding:error: 

例のコードに置き換えられているあなたは、おそらく非同期要求でその行を交換する必要があります

NSError* error = nil; 
NSString* locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSASCIIStringEncoding error:&error]; 
+0

ねえ、ありがとう! –

0

stringWithContentsOfURLのドキュメントを確認してください。 NSStringのドキュメントでは、廃止予定のものを置き換えるためにどのようなメソッドが使用されているかを正確に伝えています。この種のもののためにドキュメントをチェックする方法をよく知っておいてください。

関連する問題