如何使NSURLSession以一定的间隔重复?

时间:2022-09-03 21:44:23

I am interesting to make NSSession repeat itself at a certain interval without using an NSTimer object, I am looking if I can set some property of the NSURLRequest or of the NSURLSessionConfiguration that I have overlooked?

我很有兴趣让NSSession在不使用NSTimer对象的情况下以一定的间隔重复自己,我正在寻找是否可以设置我忽略的NSURLRequest或NSURLSessionConfiguration的某些属性?

1 个解决方案

#1


1  

if you don't want to use NSTimer, you can use long pool technic, in which you can configure the timeoutinterval.

如果您不想使用NSTimer,则可以使用长池技术,您可以在其中配置timeoutinterval。

(void)longPoll
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableURLRequest *request    = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30];

// --- Your code ---

[request release];
[pool drain];

[self performSelectorInBackground:@selector( longPoll ) withObject:nil];
}

#1


1  

if you don't want to use NSTimer, you can use long pool technic, in which you can configure the timeoutinterval.

如果您不想使用NSTimer,则可以使用长池技术,您可以在其中配置timeoutinterval。

(void)longPoll
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableURLRequest *request    = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30];

// --- Your code ---

[request release];
[pool drain];

[self performSelectorInBackground:@selector( longPoll ) withObject:nil];
}