2

アプリケーションで最新の GoogleMaps iOS SDK を使用していますが、最新の iOS アップデート 7.0.3 の後、最初のタッチ後に応答しなくなりました。これについて詳しく説明しましょう。マップを最初にタッチすると、マップが反応しなくなります。最初は、ズーム、ドラッグ、スワイプ、その他すべてをピンチできますが、最初のタッチの後、機能しなくなります。これは、Apple が iOS をアップデートした後に発生し始めました。iOS6のシミュレーターを使えば、最初のタッチからでも全てのジェスチャができます。これが iOS の更新によるものなのか、コードに問題があるのか​​ はわかりません。誰かが私を導くことができる提案を持っているか、このようなことを経験したことがあれば、それは大歓迎です. 前もって感謝します。

ここのウェブサイトの指示に従いました: ( https://developers.google.com/maps/documentation/ios/start#adding_the_google_maps_sdk_for_ios_to_your_project )

iOS6で動作し、以前はiOS7で動作していました。MapsViewController.m

#import "MapsViewController.h"
#import <GoogleMaps/GoogleMaps.h>
@interface MapsViewController ()
@end
@implementation MapsViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.storeNamesArray        = [[NSMutableArray alloc] init];
    self.storePricesArray       = [[NSMutableArray alloc] init];
    self.storeLatitudeArray     = [[NSMutableArray alloc] init];
    self.storeLongitudeArray    = [[NSMutableArray alloc] init];
    self.priceTypeArray         = [[NSMutableArray alloc] init];

    dispatch_async(dispatch_get_main_queue(), ^{ NSData *data = 
    [NSData dataWithContentsOfURL:[NSURL URLWithString:
    [NSString stringWithFormat: @"http://www.someurl.com/mobile-api"]]]; 
    [self performSelectorOnMainThread:@selector(fetchData:) withObject:data
    waitUntilDone:YES]; });
}

-(void)fetchData:(NSData *)responseData
{
    if (responseData)
    {
        NSError *error;
        NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
        NSDictionary *stores =[json objectForKey:@"stores"];
        for(NSDictionary *location in stores)
        {
            [self.storeNamesArray addObject:[location objectForKey:@"name"]];
            [self.storePricesArray addObject:[location objectForKey:@"price"]];
            [self.storeLatitudeArray addObject:[location objectForKey:@"latitude"]];
            [self.storeLongitudeArray addObject:[location objectForKey:@"longitude"]];
            [self.priceTypeArray addObject:[location objectForKey:@"price_type"]];
        }
    }
    double lat = 0.0;
    double lon = 0.0;
    GMSCameraPosition *camera;
    if(self.currentLocationArray.count !=0)
    {
        lat = [self.currentLocationArray[0] doubleValue];
        lon = [self.currentLocationArray[1] doubleValue];
        camera = [GMSCameraPosition cameraWithLatitude:lat longitude:lon zoom:12];
    }
    else
    {
        lat = [self.storeLatitudeArray[0] doubleValue];
        lon = [self.storeLongitudeArray[0] doubleValue];
        camera = [GMSCameraPosition cameraWithLatitude:lat longitude:lon zoom:9];
    }
    GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    for(int i=0; i<self.storeNamesArray.count; i++)
    {
        GMSMarker *marker = [[GMSMarker alloc] init];
        marker.title = self.storeNamesArray[i];
        marker.snippet = [NSString stringWithFormat:@"%@ $%@", self.priceTypeArray[i], self.storePricesArray[i]];
        marker.position = CLLocationCoordinate2DMake([self.storeLatitudeArray[i] doubleValue], [self.storeLongitudeArray[i] doubleValue]);
        marker.map = mapView;
    }
    if(self.currentLocationArray.count !=0)
    {
        GMSMarker *currentMarker = [[GMSMarker alloc] init];
        currentMarker.title = @"Current Location";
        currentMarker.snippet = @"You are here";
        currentMarker.position = CLLocationCoordinate2DMake(lat, lon);
        currentMarker.map = mapView;
        currentMarker.icon = [UIImage imageNamed:@"temp_userLocation"];
        mapView.selectedMarker = currentMarker;
    }
    CGRect newFrame = self.view.bounds;
    newFrame.size.height = frame.size.height / 2;
    mapView.frame = newFrame;
    mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin;
    mapView.delegate = self;
    [self.view addSubview:mapView];
}
4

3 に答える 3

0

ここに当てはまるかどうかはわかりませんが、iOS 7.0.3 でのみ表示される URLWithString 関数で同じ問題が発生しました。Apple がこの関数が使用できる文字を変更したと想定しているため、nil が返された場合、これが解決策です。

私がしたことは、URLWithString で使用する前に、この関数を使用して文字列を作成することです。

-(NSString *) URLEncodeString:(NSString *) str // New to fix 7.0.3 issue //
{

    NSMutableString *tempStr = [NSMutableString stringWithString:str];
    [tempStr replaceOccurrencesOfString:@" " withString:@"+" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [tempStr length])];


    return [[NSString stringWithFormat:@"%@",tempStr] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}

あなたのケースでは、行を次のように変更してください。

dispatch_async(dispatch_get_main_queue(), ^{ NSData *data = 
[NSData dataWithContentsOfURL:[NSURL URLWithString:[self URLEncodeString: [NSString stringWithFormat: @"http://www.someurl.com/mobile-api"]]]]; 
[self performSelectorOnMainThread:@selector(fetchData:) withObject:data
waitUntilDone:YES]; });

それもあなたに役立つことを願っています。

于 2013-11-06T20:13:05.373 に答える