尝试下载文件时出现Swift Alamofire错误

时间:2018-09-07 21:59:35

标签: ios swift alamofire info.plist

我想在Swift 4中通过Alamofire从URL下载文件。 我是新手,经过数小时的尝试,我试图找出如何安装Alamofire库,但现在我在代码中遇到了错误。 这是代码:

let destination = DownloadRequest.suggestedDownloadDestination(for: .documentDirectory)
        Alamofire.download(
            "http://handasaim.co.il/wp-content/uploads/2018/08/6-9.xls",
            method: .get,
//            parameters: parameters,
            encoding: JSONEncoding.default,
            headers: nil,
            to: destination).downloadProgress(closure: { (progress) in
                //progress closure
            }).response(completionHandler: { (DefaultDownloadResponse) in
                //here you able to access the DefaultDownloadResponse
                //result closure
            })

我得到的错误:

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
2018-09-08 00:51:39.326074+0300 TrollingWithRoss[24805:2369287] Cannot start load of Task <CFB04BFF-0724-4AC2-84BA-74E56FFF821B>.<1> since it does not conform to ATS policy
2018-09-08 00:51:39.326266+0300 TrollingWithRoss[24805:2369283] Task <CFB04BFF-0724-4AC2-84BA-74E56FFF821B>.<1> finished with error - code: -1022

我需要对“ info.plist”文件进行哪些更改?

文件:

<?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>CFBundleDevelopmentRegion</key>
    <string>$(DEVELOPMENT_LANGUAGE)</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIMainStoryboardFile</key>
    <string>Main</string>
    <key>UIRequiredDeviceCapabilities</key>
    <array>
        <string>armv7</string>
    </array>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>

</dict>
</plist>

如果我的代码不正确,请更正,我还是新手。

谢谢

没事

1 个答案:

答案 0 :(得分:0)

添加您的plist文件并解决问题:)“ Swift 4”

java.time.Duration