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