English 中文(简体)
如何更新地点管理人员和时间,以了解背景模式?
原标题:How can i update location manager and a timer in my app when it goes to background mode?

我有一段时间,显示用户的安保时间。 当我看重背景模式时,地点主管和时间主管停止更新。 在我评估背景时,如何更新这些内容?

我的看法是,RunViewController已经开了顿。 当用户点击该纽顿时,时间和地点管理人员就开始。 法典是:

 -(void)startRun{
    timeSec = 0;
    timeMin = 0;
    timeHour = 0;

    NSString* timeNow = [NSString stringWithFormat:@"%02d:%02d:%02d",timeHour , timeMin, timeSec];
    //Display on your label
    lblTime.text = timeNow;

    timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerTick:) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];

    self.locManager = [[CLLocationManager alloc] init];
    locManager.delegate = self;
    locManager.desiredAccuracy = kCLLocationAccuracyBest; //kCLLocationAccuracyBest
    [locManager setDistanceFilter:3]; //kCLDistanceFilterNone

    [locManager startUpdatingLocation];
    locationManagerStartDate = [[NSDate date] retain];


}

地点 管理者:CLLoc 经理*

简单地从旧地点到新地点绘制地图线,在阵列中拯救这一位置。

提前感谢。

问题回答

在果树开发论坛的帮助下,找到实现这一目标的解决方案。 我做了以下工作:

  • 具体地点背景模式

  • 在背景中使用NStimer

  • UIApplication:beginBackgroundTaskWithExpirationHandler: 无

smaller than UIApplication:backgroundTimeRemaining it does works just fine, in case n is larger, the location manager should be enabled (and disabled) again before there is no time remaining to avoid the background task being killed. This does work since location is one of the three allowed types of background execution.

注:通过在模拟器中测试这种时间,在拖拉机工作时,用我的电话进行罚款。

此处为

Try this..

-(void)viewDidLoad
{
    UIDevice* device = [UIDevice currentDevice];
    BOOL backgroundSupported = NO;
    if ([device respondsToSelector:@selector(isMultitaskingSupported)])
        backgroundSupported = device.multitaskingSupported;

    NSLog(backgroundSupported ? @"Yes" : @"No");


    counterTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
     //called after 10min of your app in background
        NSLog(@"10 minutes finished.");
    }];

    theTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(selectorForUpdatingLocation) userInfo:nil repeats:YES];

}




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签