OGeek|极客世界-中国程序员成长平台

标题: ios - 如何让 NSURLSession 以一定的间隔重复? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 06:30
标题: ios - 如何让 NSURLSession 以一定的间隔重复?

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



Best Answer-推荐答案


如果你不想使用 NSTimer,你可以使用 long pool 技术,你可以在其中配置 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 performSelectorInBackgroundselector( longPoll ) withObject:nil];
}

关于ios - 如何让 NSURLSession 以一定的间隔重复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29747207/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4