Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

11.2.4后台运行 #12

Open
jobsLee-lcj opened this issue Dec 14, 2015 · 0 comments
Open

11.2.4后台运行 #12

jobsLee-lcj opened this issue Dec 14, 2015 · 0 comments

Comments

@jobsLee-lcj
Copy link

让程序在后台长久运行的示例代码如下:

- (void)applicationDidEnterBackground:(UIApplication *)application {
  [self beingBackgroundUpdateTask];
 //在这里加上你需要长久运行的代码
  [self endBackgroundUpdateTask];
}

- (void)beingBackgroundUpdateTask {
    self.backgroundUpdateTask =  [[UIApplication shareApplication] beginBackgroundTaskWithExpirationHandler:^{
    [self endBackgroundUpdateTask];
}];
}

- (void)endBackgroundUpdateTask {
    [[UIApplication sharedApplication]  endBackgroundTask:self.backgroundUpdateTask];
    self.backgroundUpdateTask = UIBackgroundTaskInvalid;
}

1.作者第一个方法是不是想写成beginBackgroundUpdateTask以与end对应啊?
2.在beingBackgroundUpdateTask的expirationHandler中有调用endBackgroundUpdateTask,而在applicationDidEnterBackground中也有调用,这样重复调用不会有问题么?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant