在Playground中调用异步NSURLSession的问题

时间:2016-02-01 22:03:31

标签: ios xcode swift nsurlsession swift-playground

我正在尝试在IOS中实施自定义Google搜索。为了测试,我试图在Playground中测试请求。我的搜索URL在浏览器中工作正常(chrome),但是在游乐场中,完成块没有触发,我在控制台中得到这个:(即使在重新启动Xcode之后)

2016-02-01 17:00:07.059 GooglePlayground[23603:5654691] 
Failed to obtain sandbox extension for path=
/var/folders/1q/fvvgmbxd7zvbl2s0d307pb8m0000gn/T/com.apple.dt.Xcode.pg/containers/com.apple.dt.playground.stub.iOS_Simulator.GooglePlayground-8B924AAB-7245-42E2-8771-B5E36703E579/Library/Caches/com.apple.dt.playground.stub.iOS_Simulator.GooglePlayground-8B924AAB-7245-42E2-8771-B5E36703E579. 
Errno:1

代码:

import UIKit
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true



let SearchEngineID = "XXXXX"
let APIKey = "XXXXX"
let searchText = "steelers"
let googleURL = "https://www.googleapis.com/customsearch/v1?q=" + searchText + "&key=" + APIKey + "&cx=" + PinCheckSearchEngineID

var nsURL = NSURL(string: googleURL)
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(nsURL!, completionHandler: {(data, response, error) in
    print("data = \(data)")
})

task.resume()

0 个答案:

没有答案