【问题标题】:Gps location icon is not offGps 位置图标未关闭
【发布时间】:2012-10-27 04:45:05
【问题描述】:

在我的应用程序中,我实现了 Cllocation 管理器以使用当前用户位置并且它工作正常。但是当应用程序进入后台或终止时,GPS位置图标会自动隐藏在ipod中。当我尝试使用 Iphone 时,图标没有隐藏。

所以,我找不到任何解决方案。帮帮我!!

我的代码如下:

AppDelegate.m

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
     self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

if(locationManager == nil)

        locationManager =[[CLLocationManager alloc] init];

    self.locationManager.delegate = self;

    self.locationManager.desiredAccuracy= kCLLocationAccuracyBest;

    self.locationManager.distanceFilter= 5;

    [locationManager startUpdatingLocation];
    [locationManager startUpdatingHeading];
}


-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{

    self.userLocation=newLocation;

    [self.locationManager startMonitoringSignificantLocationChanges];
}

地图.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [APPDELEGATE.locationManager startUpdatingLocation];

}

- (void)viewWillAppear:(BOOL)animated
{
    self.map.delegate = self;

    [self.map setShowsUserLocation:YES];
}

如果我在 ipod 中手动为我的应用程序启用位置服务,当应用程序关闭时,它不会显示位置图标。但是当我在 iphone 中尝试相同时,它会显示位置图标。

【问题讨论】:

    标签: iphone ios xcode cllocationmanager


    【解决方案1】:

    最后我解决了这个问题,如下所示。

    代替

    [self.locationManager startMonitoringSignificantLocationChanges]; 
    

    在应用程序中

    我写,

    [self.locationManager stopMonitoringSignificantLocationChanges];
    

    【讨论】:

      【解决方案2】:

      我认为你真正想要的是:

      [self.locationManager stopUpdatingLocation];
      

      之后,如果您希望经理在位置发生重大变化时醒来,请致电:

      [self.locationManager startMonitoringSignificantLocationChanges];
      

      相反的情况适用于返回持续更新:

      [self.locationManager stopMonitoringSignificantLocationchanges];
      [self.locationManager startUpdatingLocation];
      

      注意:在重大位置更改模式下,状态栏中的图标仍将显示与连续更新位置时相同。这不是一个值得关注的问题,因为在保守模式下,它仍然会在不需要时关闭定位服务。
      ipod 不支持 startMonitoringSignificantLocationChanges。这就是指标在两种设备上表现不同的原因。

      您应该考虑到,当您实施它时,您正在使用第一个事件报告的任何内容来获取管理器之外的位置。这通常可能是陈旧的、缓存的、陈旧的或很可能非常不准确。标准做法是进行一些测试,并根据您的目的提供更合适的位置信息。

      在您使用定位服务时,请参阅 Github 上的 my handler 以获得更多帮助。

      【讨论】:

        猜你喜欢
        • 2023-04-04
        • 1970-01-01
        • 1970-01-01
        • 2012-03-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多