gpt4 book ai didi

iphone - 如何在ios5中每30秒在后台运行我的应用程序一次?

转载 作者:行者123 更新时间:2023-12-01 18:30:45 24 4
gpt4 key购买 nike

我已经在ios5中实现了长期运行的处理方法。我想在应用程序处于后台运行时每30秒或1分钟触发一些功能。我编写了执行长时间运行过程的代码,方法是进入后台方法,进入后我无法执行计时器功能背景。我应该在哪里放置我的计时器函数,以便它应该调用目标方法,即使它在后台也是如此。

 bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
// Clean up any unfinished task business by marking where you.
// stopped or ending the task outright.

[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];


dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(targetMethod) userInfo:nil repeats:YES];
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});

这个怎么做?一些示例代码会有所帮助。

谢谢
普什帕

最佳答案

您只能在后台支持定位服务,音频播放和VOIP服务。
如果您的应用程序不使用这些API及其功能中的任何一个,那么请不要浪费您的时间...即使有某种方法,Apple也不会接受您的应用程序。

关于iphone - 如何在ios5中每30秒在后台运行我的应用程序一次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9171508/

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