我有一个Alamofire请求,它应该下载一个文件,但是它不会执行它自己的代码。这是“阿拉莫火灾守则”:
var testNumbers: Int = 0
var testString: String = "Hi"
Alamofire.download(.GET, "http://www.sayweee.com/admin_groupbuy/export_deal_orders/71w4o?format=csv") { temporaryURL, response in
let fileManager = NSFileManager.defaultManager()
let directoryURL = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
let pathComponent = response.suggestedFilename
print("1")
testNumbers = 1
print(directoryURL.URLByAppendingPathComponent(pathComponent!))
print("blah")
testString = "blah"
print("2")
testNumbers = 2
return directoryURL.URLByAppendingPathComponent(pathComponent!)
}
print(testNumbers)
print(testString)执行此代码将在控制台中打印此代码:
0
Hi我确信这意味着{}中的代码不会被执行。我读过关于这个主题的另一篇文章,并了解到Alamofire是“异步的”,就像他们在this post中所说的那样。我试图消除viewDidLoad()方法和viewDidAppear()方法中的所有内容,并确保没有任何无穷尽的循环。即使在那之后,结果也是一样的。对于为什么会发生在我身上,有什么想法或建议吗?我试着在这里和谷歌上查找,但我只找到了一个与这个主题有关的帖子,上面链接的那个。
发布于 2015-12-30 07:11:09
首先,我将您的代码放在Demo中运行,找到了运行的结果,您说的是相同的,如下图所示:0 Hi 2015-12-30 14:31:29.873 iOS Example[3966:142688] 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.
根据提示,您将看到问题: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.
解决方案如下(在项目文件"info.plist“中):In project's "info.plist" file to add a "NSAppTransportSecurity" dictionary, an element is added in the dictionary.Key for "NSAllowsArbitraryLoads", the value is: YES, make it back to the HTTP protocol for the time being.
问题解决方案链接:
Transport security has blocked a cleartext HTTP
最后的结果如下:
0 Hi 1 file:///Users/yangshebing/Library/Developer/CoreSimulator/Devices/151CB429-29B3-46D0-AFF5-37D5B8D9E4FC/data/Containers/Data/Application/756A32D1-64C5-48CF-B652-D3009D80780D/Documents/71w4o.html blah 2
具体问题你可以去查询苹果官方文档,查询iOS9自动测试系统适应问题。
希望能帮助你!
https://stackoverflow.com/questions/34522528
复制相似问题