【问题标题】:App Transport Security if I Don’t Know All the Insecure Domains I Need to Use如果我不知道我需要使用的所有不安全域,应用程序传输安全性
【发布时间】:2016-03-05 09:31:34
【问题描述】:

我已经看到这个问题在某种程度上回答了here,但在我的情况下,我使用 NSURLSession 来显示图像。这些图像由用户上传或使用脚本扫描到数据库中。

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

我不确定最好的方法。任何意见将不胜感激!

这是我正在使用的代码。

    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];

【问题讨论】:

  • NSAllowsArbitraryLoads 完全是supported by Apple,因此是的,您可以使用它提交您的应用到 AppStore。

标签: ios objective-c app-transport-security


【解决方案1】:

是的,即使使用此参数,您也会通过审核。 自 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];

【讨论】:

    猜你喜欢
    • 2015-12-19
    • 2019-03-07
    • 1970-01-01
    • 2016-11-11
    • 1970-01-01
    • 2016-01-08
    • 2017-04-26
    • 1970-01-01
    • 2017-06-10
    相关资源
    最近更新 更多