2

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?

Jay Mehta
  • 1,431
  • 19
  • 40
Laur Stefan
  • 1,519
  • 5
  • 23
  • 50
  • In what conditions do you want to repeat ? Is there any event? or Change in some variable's value ? – Vinay Jain Apr 20 '15 at 12:51
  • so if I am on a certain view I just want to make a post to the server at an interval(let's say 5 min) and retrieve some data, I am not interested in background fetching – Laur Stefan Apr 20 '15 at 12:56
  • 2
    as you are certain about the time interval, why don't you do it with NSTimer. Are you facing any problem with that? – Vinay Jain Apr 20 '15 at 13:01

1 Answers1

1

if you don't want to use NSTimer, you can use long pool technic, in which you can configure the 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];
}
Clo
  • 21
  • 1