在 iOS 中,我正在尝试下载图像,但我需要传入访问令牌。通常,我使用此代码下载图像(忽略:
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
NSString *curURL = [NSString stringWithFormat:@"https://myBaseURL.com/img.png"];
NSLog(@"cur url: %@", curURL);
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:curURL]];
dispatch_sync(dispatch_get_main_queue(), ^{
self.propImg1.image = [UIImage imageWithData:data];
[self.propImg1 setNeedsLayout];
});
});
有没有人对如何传递访问令牌有任何建议或更好的示例代码?