gpt4 book ai didi

iphone - 在后台状态下安排重复任务。 (iOS)

转载 作者:行者123 更新时间:2023-11-28 17:33:53 25 4
gpt4 key购买 nike

如果我的研究是正确的,那么当您的应用程序在后台时它真的被暂停了。 Apple 支持的后台任务方法是位置、音频和 SIP 类型的应用程序,这是正确的吗?

是否有任何 Apple 支持的方法可以在后台每 60 秒运行一次方法,我需要检查服务器的状态。下面的代码可以满足我的需要,但在 10 分钟后停止,我认为这是另一种 Apple 支持的方法。关于这是否可能的任何建议或确认都会有所帮助。

下面的代码只是创建了一个每 10 秒运行一次的任务并更新角标(Badge)计数。

问候

- (void)viewDidLoad
{
[super viewDidLoad];

count=0;
counterTask = [[UIApplication sharedApplication]
beginBackgroundTaskWithExpirationHandler:^{
// If you're worried about exceeding 10 minutes, handle it here
}];
theTimer=[NSTimer scheduledTimerWithTimeInterval:5
target:self
selector:@selector(countUp)
userInfo:nil
repeats:YES];
}

- (void)countUp {
NSLog(@"%s - %d", __FUNCTION__, count + 1 );

if (count==1000) {
[theTimer invalidate];
[theTimer release];
[[UIApplication sharedApplication] endBackgroundTask:counterTask];
} else {
count++;
NSString *currentCount;
currentCount=[[NSString alloc] initWithFormat:@"%d",count];
[currentCount release];
[UIApplication sharedApplication].applicationIconBadgeNumber = count;

}
}

最佳答案

不幸的是,我也在我的应用程序中使用了这个 10 分钟的后台任务,根据我所做的研究,这是在后台运行方法的唯一方法。希望能回答您的问题

关于iphone - 在后台状态下安排重复任务。 (iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10403904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com