Invoke get current coordinates every few seconds without NSTimer

后端 未结 2 401
别跟我提以往
别跟我提以往 2021-01-15 03:45

I know how to make this with NSTimer but I wan\'t to get current iPhone coordinates without timer on every few seconds. I can\'t use timer because I am getting coordinates w

2条回答
  •  清酒与你
    2021-01-15 04:27

    I think you can do it in background with a Timer:

    [NSTimer scheduledTimerWithTimeInterval:kAlertInterval target:self selector:@selector(checkLoc:) userInfo:nil repeats:YES];
    

    And in your method:

    - (void)checkLoc:(NSTimer *)timer {
        //...get your location and...
         if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
            //Do your background stuff
        }
    }
    

    I have this code working in some apps. Please, tell me if it works for you.

提交回复
热议问题