第一个问题:使用Core Locatin框架时,有时UI会卡住,请问是网络问题吗?定位时是异步的吗?
由于不知道是否异步,所以用了多线程,代码如下:
dispatch_queue_t where = dispatch_queue_create("where", nil);
dispatch_async(where, ^{
_whereAmI = [[WhereAmI alloc] init];//进入定位,启动定位代码在init中
//下面是注线程,刷新UI的
dispatch_async(dispatch_get_main_queue(), ^{
ModifyViewController *modifyViewController = [[ModifyViewController alloc] init];
modifyViewController.ispushed = YES;
[STHUnity sthPushViewController:self viewController:modifyViewController];
});
});第二个问题:第一次使用GCD,不知用对否?给个说明。因为我用上面的代码,定位一直启动不了,当把GCD的几句代码去掉后,能启动定位,但是那样就回到第一个问题了,求解!!!
由于不知道是否异步,所以用了多线程,代码如下:
dispatch_queue_t where = dispatch_queue_create("where", nil);
dispatch_async(where, ^{
_whereAmI = [[WhereAmI alloc] init];//进入定位,启动定位代码在init中
//下面是注线程,刷新UI的
dispatch_async(dispatch_get_main_queue(), ^{
ModifyViewController *modifyViewController = [[ModifyViewController alloc] init];
modifyViewController.ispushed = YES;
[STHUnity sthPushViewController:self viewController:modifyViewController];
});
});第二个问题:第一次使用GCD,不知用对否?给个说明。因为我用上面的代码,定位一直启动不了,当把GCD的几句代码去掉后,能启动定位,但是那样就回到第一个问题了,求解!!!
- (id)init
{
self = [super init];
if (self) {
_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[_locationManager startUpdatingLocation];
}
return self;
}
注:如果取消GCD,直接把init放在主线程中,定位是可以启动的
定位为异步回调方式,所以直接放主线程启动即可。
这里完成不需要使用GCD来处理。