閱讀544 返回首頁    go 阿裏雲 go 技術社區[雲棲]


server did not accept client registration 68解決方法

想在iOS上獲取城市名稱,采用了一個方法


- (void)startedReverseGeoderWithLatitude:(double)latitude longitude:(double)longitude{

    CLLocationCoordinate2D coordinate2D;

    coordinate2D.longitude = longitude;

    coordinate2D.latitude = latitude;

    MKReverseGeocoder *geoCoder = [[MKReverseGeocoder alloc] initWithCoordinate:coordinate2D];

    geoCoder.delegate = self;

    [geoCoder start];

}

#pragma mark -

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark

{

    NSString *subthroung=placemark.subThoroughfare;

    NSString *local=placemark.locality;

    NSLog(@"城市名:%@-%@-%@",placemark.locality,local,subthroung);

    if (local) {

       [cityLabel setText:local];

    }

}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error

{

}

 

原文參考:https://blog.csdn.net/diyagoanyhacker/article/details/6412557

上麵的文章隻給了一個實現類,對於新手來說,比較困難。

我在補充下,

增加框架,coreLocation.framework,MapKit.framework框架。

在實現文件中包括

#import <CoreLocation/CoreLocation.h>
#import <Mapkit/Mapkit.h>

同時增加委托

CLLocationManagerDelegate,MKReverseGeocoderDelegate>

直接編譯運行,出現

server did not accept client registration 68

經過google,終於找到這是個bug。原文 https://forums.bignerdranch.com/viewtopic.php?f=79&t=2069


解決方法在,實現文件的的#import 和 @implementation 之間增加如下代碼(hach crash)

@implementation CLLocationManager (TemporaryHack)

- (void)hackLocationFix
{
    CLLocation *location = [[CLLocation alloc] initWithLatitude:42 longitude:-50];
    [[self delegate] locationManager:self didUpdateToLocation:location fromLocation:nil];     
}

- (void)startUpdatingLocation
{
    [self performSelector:@selector(hackLocationFix) withObject:nil afterDelay:0.1];
}

經過重重磨難,終於跑起來了,也獲得了經緯度,不過悲劇的是reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark ,方法沒有執行。難道是模擬器的是?回家放到設備上看看去~



最後更新:2017-04-02 22:16:40

  上一篇:go java反射3——類實例的方法1
  下一篇:go 使用github管理iOS分布式項目開發