Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在后台状态下安排重新出现的任务。(iOS)_Iphone_Objective C_Ios_Ipad_Scheduled Tasks - Fatal编程技术网

Iphone 在后台状态下安排重新出现的任务。(iOS)

Iphone 在后台状态下安排重新出现的任务。(iOS),iphone,objective-c,ios,ipad,scheduled-tasks,Iphone,Objective C,Ios,Ipad,Scheduled Tasks,如果我的研究是正确的,当你的应用程序是在后台,它是真的暂停。Apple支持的后台任务方法是位置、音频和SIP类型的应用程序,对吗 是否有任何苹果支持的方法可以每60秒运行一个方法,而在后台,我需要检查服务器的状态。下面的代码做了我需要的,但在10分钟后停止,我相信这是另一个苹果支持的方法。任何关于这是否可能的建议或确认都会有所帮助 下面的代码只是创建一个每10秒运行一次的任务,并更新徽章计数 问候 - (void)viewDidLoad { [super viewDidLoad];

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

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

下面的代码只是创建一个每10秒运行一次的任务,并更新徽章计数

问候

- (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分钟的后台任务,根据我所做的研究,这是在后台运行方法的唯一方法。希望这能回答你的问题