gpt4 book ai didi

iphone - 如何在所有应用程序上接收重大位置更改,而不是仅在一个 View 上接收?

转载 作者:行者123 更新时间:2023-11-28 22:53:57 24 4
gpt4 key购买 nike

我是 iOS 编程的新手,我需要实现一个位置感知应用程序。我已经可以使用重要的位置更改服务,但是当我离开我的 View 时,它会停止接收新的更新。

如果我在那个 View 上输入背景,我仍然会得到更新并且一切都很好,但是如果我将我的 View 更改为其他 View ,它就会停止...

我认为以这种方式发生是合乎逻辑的,但我也需要接收有关我其他观点的更新...

我应该为我拥有的每个 View 复制代码,还是可以让我在任何 View 中接收更新,比如让我的应用程序回答而不是每个 View 。

谢谢,阵风

最佳答案

在AppDelegate.m中加入这段代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:  (NSDictionary *)launchOptions
{
if(!locationManager) {
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
}
}

- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
//here you will get upadated location
//here you can add delegate method call to where you want to use this location or you can create a shared variable

}

关于iphone - 如何在所有应用程序上接收重大位置更改,而不是仅在一个 View 上接收?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11204319/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com