我对 dispatch_queue_t 队列有一些问题。我试图为我的问题找到完美的解决方案,但我找到了加载 UIImage 或其他元素但不是 NSURL 的解决方案。所以我有简单的 NSURL 和简单的网站:
NSURL *url = [NSURL URLWithString:@"site.ch"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
我需要我的 NSURL(这个代码)将在例如 10 分钟后重新启动,所以我放了 NSTimer,但是为了更新这个 NSURL,我尝试使用这个代码,但我也有错误..
-(void)updateRadio
{
dispatch_queue_t queue = dispatch_get_global_queue(0,0);
dispatch_async(queue, ^{
NSError* error = nil;
NSString* text = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"site.ch"]
encoding:NSASCIIStringEncoding
error:&error];
// checking if error == nil would be appropriate
dispatch_async(dispatch_get_main_queue(), ^{
});
});
}
所以我需要把 NSURL With Request 放到这个代码中。不是 NSString 只有 NSURL 这是怎么弄的?谢谢。