NSURLSession - DownloadTask不适用于某些URL

时间:2016-12-02 13:22:51

标签: ios swift

  • 这里是代码:

    <div ng-controller="HomeController">        
        <script type="text/ng-template" id="buttonTemplate.html">
            <button class="btn btn-sm btn-danger" ng-click="cellTemplateScope.doSomething()">Do Something</button>
        </script>
    
        <tree-grid tree-data="yourTreeData" col-defs="col_defs"></tree-grid>
    </div>
    

- &GT;行

- &GT;它不起作用;没有任何反应

3 个答案:

答案 0 :(得分:1)

默认情况下,从iOS 9开始,所有连接都必须为https。如果第二个URL的网站不支持https://则下载将失败。

我建议您检查从下载中获取的错误代码

答案 1 :(得分:0)

如果要使用带有HTTP连接的URL,请在info.plist文件中添加以下内容 应用程序传输安全设置和添加子部分允许任意加载并将值设置为YES。

enter image description here

答案 2 :(得分:-2)

请加入Plist

- (void)deleteImageForButton:(UIButton *)button{
    [self.imageArray removeObjectAtIndex:button.tag];
    [button removeFromSuperview];
    for(long i=button.tag + 1; i<= self.imageArray.count ; i++)
    {
        UIButton *button = (UIButton *)[self.view viewWithTag:i];
        button.tag = button.tag - 1;
        [button setImage:self.imageArray[button.tag] forState:UIControlStateNormal];
    }
}

然后使用Alamofire 4.0 Swift 3.0

使用以下方法,你可以下载任何东西,例如。 PDF

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSExceptionDomains</key>
    <dict>
        <key>akamaihd.net</key>
        <dict>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
            <key>NSIncludesSubdomains</key>
            <true/>
        </dict>
        <key>facebook.com</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
            <key>NSIncludesSubdomains</key>
            <true/>
        </dict>
        <key>fbcdn.net</key>
        <dict>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
            <key>NSIncludesSubdomains</key>
            <true/>
        </dict>
        <key>graph.facebook.com</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
            <key>NSIncludesSubdomains</key>
            <true/>
        </dict>
    </dict>
</dict>
</plist>