Ios 在后台运行URL请求

Ios 在后台运行URL请求,ios,objective-c,Ios,Objective C,我希望在特定的时间间隔内发出url请求(例如,每10分钟应用程序应该发出一次url调用并获取一些json数据)。应用程序在后台运行时应该能够做到这一点。这能做到吗?如果是这样,这是否违反了苹果的服务条款?是否有任何限制?在基本级别:只需安排一个NSTimer并在timer函数上启动URL请求。如果您的目标是iOS7,那么请确保您使用的是NSURLSession。然而,重要的一点是要知道你是否想在后台做这件事。如果是,您必须了解有关iOS后台模式的更多信息,因为您将无法在此模式下维护计时器。。没有

我希望在特定的时间间隔内发出url请求(例如,每10分钟应用程序应该发出一次url调用并获取一些json数据)。应用程序在后台运行时应该能够做到这一点。这能做到吗?如果是这样,这是否违反了苹果的服务条款?是否有任何限制?

在基本级别:只需安排一个NSTimer并在timer函数上启动URL请求。如果您的目标是iOS7,那么请确保您使用的是NSURLSession。然而,重要的一点是要知道你是否想在后台做这件事。如果是,您必须了解有关iOS后台模式的更多信息,因为您将无法在此模式下维护计时器。。没有任何内容会导致拒绝。

在基本级别:只需安排一个NSTimer并在timer函数上启动URL请求。如果您的目标是iOS7,那么请确保您使用的是NSURLSession。然而,重要的一点是要知道你是否想在后台做这件事。如果是,您必须了解有关iOS后台模式的更多信息,因为您将无法在此模式下维护计时器。。没有任何内容会导致拒绝。

我认为iOS中有一些限制,当应用程序处于后台模式时,您不能连续发送请求。当应用程序进入后台模式时,iOS允许一点时间来完成web请求。 请检查此Apple文档:
我认为iOS中有一些限制,当应用程序处于后台模式时,您不能连续发送请求。当应用程序进入后台模式时,iOS允许一点时间来完成web请求。 请检查此Apple文档:
ios 7新增了可在后台运行的应用程序列表。它们是:

1.  Apps that play audible content to the user while in the background, such as a music player app
2.  Apps that record audio content while in the background.
3.  Apps that keep users informed of their location at all times, such as a navigation app
4.  Apps that support Voice over Internet Protocol (VoIP)
5.  Apps that need to download and process new content regularly
6.  Apps that receive regular updates from external accessories
我们只需要在info.plist中声明应用程序支持的后台任务。我们需要补充一点 ui背景模式键指向我们应用程序的信息。plist。之后,您可以正常使用计时器,如:

UIBackgroundTaskIdentifier bgTask;

UIApplication  *app = [UIApplication sharedApplication];

bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
    [app endBackgroundTask:bgTask]; 
}];

self.timer = [NSTimer scheduledTimerWithTimeInterval:600 target:self
selector:@selector(startServices) userInfo:nil repeats:YES];

希望它能对您有所帮助。

ios 7新增了可在后台运行的应用程序列表。它们是:

1.  Apps that play audible content to the user while in the background, such as a music player app
2.  Apps that record audio content while in the background.
3.  Apps that keep users informed of their location at all times, such as a navigation app
4.  Apps that support Voice over Internet Protocol (VoIP)
5.  Apps that need to download and process new content regularly
6.  Apps that receive regular updates from external accessories
我们只需要在info.plist中声明应用程序支持的后台任务。我们需要补充一点 ui背景模式键指向我们应用程序的信息。plist。之后,您可以正常使用计时器,如:

UIBackgroundTaskIdentifier bgTask;

UIApplication  *app = [UIApplication sharedApplication];

bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
    [app endBackgroundTask:bgTask]; 
}];

self.timer = [NSTimer scheduledTimerWithTimeInterval:600 target:self
selector:@selector(startServices) userInfo:nil repeats:YES];

希望它能对你有所帮助。

是的,可以做到……我不认为苹果会拒绝应用程序,因为有很多应用程序支持后台模式。如果你通过应用程序审查指南,那就太好了。。!是的,这是可以做到的…我不认为苹果会拒绝应用程序,因为有很多应用程序支持后台模式运行。如果你通过应用程序审查指南,这将是一件好事。。!谢谢你的详细回答。是的,我需要应用程序在后台模式下运行。实际需求是,我想跟踪用户当前位置,并每10分钟向服务器发送一次详细答案。是的,我需要应用程序在后台模式下运行。实际需求是,我想跟踪用户的当前位置,并每10分钟发送一次到服务器非常感谢您的详细回答非常感谢您的详细回答