【问题标题】:locationmanager not stopping without using the navigationback buttonlocationmanager 不使用导航返回按钮就不会停止
【发布时间】:2013-08-21 13:41:11
【问题描述】:

在我的 iphone 应用程序中,我每隔一分钟在后台跟踪用户位置。为此,我正在使用 uiswitch。在它的帮助下,我启动/停止后台进程。当我在该跟踪选项页面中时,启动和停止完美地启动和停止后台服务。如果我转到具有该服务启动状态的另一个页面,我将无法停止该服务..该后台服务正在运行..但是使用导航控制器后退按钮,我来到该页面意味着它正在工作..所以我很困惑在哪里我错过了……请帮帮我……

【问题讨论】:

    标签: cocoa-touch cllocationmanager


    【解决方案1】:
    - (void)_stopLocation
    {
        if (__locationStarted) {
            if (![self isLocationServicesEnabled]) {
                return;
            }
    
            [self.locationManager stopUpdatingLocation];
            __locationStarted = NO;
        }
    }
    
    - (void)viewDidUnload
    {
        [super viewDidUnload];
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
        [self _stopLocation];
    }
    

    【讨论】:

    • 谢谢..但我无法理解这个..你能给出一些解释
    • -(IBAction)startTracking:(id)sender{ if(startTrackingButton.on){ [locationManager startUpdatingLocation]; [[NSUserDefaults standardUserDefaults] setBool:startTrackingButton.on forKey:@"switchValue"]; [[NSUserDefaults standardUserDefaults] 同步]; } else{ [locationManager stopUpdatingLocation]; } }
    • 在您的代码中。__locationStarted 和 isLocationServicesEnabled 是什么
    • 该死,即使我发布了一个完整的代码,因为新手开发人员无法猜出这两个可能是什么......如果 (__locationStarted) 比 __locationStarted 那是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多