等待直到在 didFinishLaunchingWithOptions 中设置当前位置
我的 Home UIView 需要当前位置坐标,并且在获得这些坐标之前我不希望调用它。我怎样才能最好地实现这一目标?
在此代码中,在更新当前位置之前调用视图:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
currentLocation = [[CLLocation alloc] init];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager startUpdatingLocation];
TTNavigator *navigator = [TTNavigator navigator];
navigator.persistenceMode = TTNavigatorPersistenceModeAll;
TTURLMap *map = navigator.URLMap;
[map from:@"tt://HomeView" toViewController: viewController];
[navigator openURLAction:[TTURLAction actionWithURLPath:@"tt://HomeView"]];
}
My Home UIView requires current Location coordinates and I wouldn't want it to be called until I have these coordinates. How best can I achieve this?
in this code, the view is called before the update of current location:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
currentLocation = [[CLLocation alloc] init];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager startUpdatingLocation];
TTNavigator *navigator = [TTNavigator navigator];
navigator.persistenceMode = TTNavigatorPersistenceModeAll;
TTURLMap *map = navigator.URLMap;
[map from:@"tt://HomeView" toViewController: viewController];
[navigator openURLAction:[TTURLAction actionWithURLPath:@"tt://HomeView"]];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用户可以关闭位置服务。所以我不会那样做..
而是检查 didFinishLaunchingWithOptions 之后的位置,这样您当前的问题就会得到解决。
并添加一个屏幕,供用户在定位服务关闭时打开它。
users can have Location service turned off. so I wouldn't do that..
Instead check for the location after the didFinishLaunchingWithOptions, so that your current problem will be solved.
and add one more screen for user to turn on the location service if it's off.