0
您好,我在iOS 6/7上获取用户当前位置时遇到问题。我需要用户在应用程序启动时的位置,但需要6-8秒才能获取用户位置,直到检索到位置为止,应用程序不会隐藏启动画面,这对我来说并不好。获取iOS 6/7后台线程中用户的当前位置
我想使用dispatch_async(GCD)获取用户在后台的位置,但它并没有改变一个东西:(所以我想知道是否有办法解决我的问题,我非常感谢任何帮助。 。提前 这里是我的应用程序的初始化代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
FinalMenuViewController *leftMenuViewController = [[FinalMenuViewController alloc] init];
MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
containerWithCenterViewController:[self navigationController]
leftMenuViewController:leftMenuViewController
rightMenuViewController:nil];
container.panMode = MFSideMenuPanModeNone;
self.window.rootViewController = container;
if(([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)){
[[UIBarButtonItem appearance] setTintColor:[UIColor whiteColor]];
}else{
[[UIBarButtonItem appearance] setTintColor:[UIColor colorWithRed:(250.0/255.0) green:(139.0/255.0) blue:(40.0/255.0) alpha:1.0]];
}
[self.window makeKeyAndVisible];
[self displaySplashImage];
[self setDefaultData];
[self initLocationManager];
return YES;
}
-(void) displaySplashImage{
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
UIImage* myImage;
NSString *imgName = ([[UIScreen mainScreen] bounds].size.height == 568) ? @"[email protected]" : @"Default.png";
myImage = [UIImage imageNamed:imgName];
self.splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.window.frame.size.width, self.window.frame.size.height)];
mainV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, screenHeight)];
[mainV addSubview:self.splashView];
[mainV setBackgroundColor: [UIColor clearColor]];
self.splashView.image = myImage;
self.splashView.contentMode = UIViewContentModeScaleAspectFit;
[self.window addSubview:mainV];
[self.window bringSubviewToFront:mainV];
[self removeImageView];
}
-(void) removeImageView{
if(mainV){
[mainV removeFromSuperview];
}
}
---编辑---- 这里是获取当前位置
-(void) initManager{
locManager_ = [[CLLocationManager alloc] init];
locManager_.delegate = self;
locManager_.distanceFilter = 50;
locManager_.desiredAccuracy = kCLLocationAccuracyBest;
[locManager_ startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_6_0){
CLLocation *loc = [locations lastObject];
GlobalVariables *vars = [GlobalVariables getInstance];
vars.currentLocatoin = loc;
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
if ([error domain] == kCLErrorDomain) {
switch ([error code]) {
case kCLErrorDenied:{
NSString *msg = @"ERROR_MSG_HERE";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:msg delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
break;
}
case kCLErrorLocationUnknown:{
NSString *msg = @"We were unable to find your location";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:msg delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
break;
}
default:
break;
}
} else {
}
}
http://stackoverflow.com/questions/8854100/async-call-a-method-using-ios-4 –
的可能的复制在这里没有足够的信息。你在initLocationManager方法中做了什么?根据这段代码,启动画面在被呈现后立即被移除,所以你的应用可能被卡在别的地方。你有没有使用仪器工具来看看哪里? – Paulw11