如果我不知道我需要使用的所有不安全域,应用程序传输安全

App Transport Security if I Don’t Know All the Insecure Domains I Need to Use

我看到这个问题得到了一定程度的回答 但在我的例子中,我使用 NSURLSession 来显示图像。这些图像由用户上传或使用脚本扫描到数据库中。

在这种情况下,写入异常 URL 的 (NSExceptionDomains) 将不起作用,因为图像由用户托管在他们的网站或其他网站上。如果我允许 NSAllowsArbitraryLoads,我是否仍然能够获得 App Store 的批准,因为我没有实施 ATS 的最佳实践?

我不确定继续的最佳方式。如有任何意见,我们将不胜感激!

这是我正在使用的代码。

    NSString *thumbnail_url = [tempObject objectForKey:@"image"];
    NSURL  *url = [NSURL URLWithString:thumbnail_url];
    NSURLSession *session = [NSURLSession sharedSession];

    NSURLSessionDownloadTask *downloadPhotoTask = [session downloadTaskWithURL:url completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
            NSData *imageData = [[NSData alloc] initWithContentsOfURL:location];
            dispatch_async(dispatch_get_main_queue(), ^{
                cell.tableImageView.image = [UIImage imageWithData:imageData];
        });
    }];

    [downloadPhotoTask resume];

是的,即使使用此参数,您也会通过审核。 自从 iOS9 SDK NSAllowsArbitraryLoads 设置为 YES.

以来,我们已经上传了许多构建

P.S.: 你的代码最好看起来像这样:

cell.thumbnailURL = URL;
__weak typeof(cell) weak
NSURLSessionDownloadTask *downloadPhotoTask = [session downloadTaskWithURL:URL completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
    NSData *imageData = [[NSData alloc] initWithContentsOfURL:location];
    UIImage *image = [UIImage imageWithData:imageData];
    dispatch_async(dispatch_get_main_queue(), ^{
        if (weakCell.thumbnailURL != URL) {
            return;
        }
        weakCell.tableImageView.image = image;
    });
}];
[downloadPhotoTask resume];