小编rec*_*rks的帖子

Swift 3:URLSession/URLRequest不起作用

我仍然试图将我们的应用程序从Swift 2转换为Swift 3,因为我被迫,因为我们所有的Apple设备现在都在运行iOS 10.

我已经完成了代码转换,并认为我做得很好,但在尝试调试我的JSON问题时(在另一个问题中发布),我现在处理的请求甚至没有被发送.

let params: [String:AnyObject] = [
    "email":"\(self.preferences.string(forKey: "preference_email")!)" as AnyObject
]
let requestParams: [String:AnyObject] = [
    "action":"601" as AnyObject,
    "params":params as AnyObject
]

do {
    let requestObject = try JSONSerialization.data(withJSONObject: requestParams, options:[])
    var request = URLRequest(url: URL(string: "http://domain.tld/path/")!)

    request.httpBody = requestObject
    request.httpMethod = "POST"

    let config = URLSessionConfiguration.default
    let session = URLSession(configuration: config)

    NSLog("Got here?")

    session.dataTask(with: request) {data, response, error in
        guard let data = data, error == nil else {
            print("error=\(error)")
            return
        }

        NSLog("Got here …
Run Code Online (Sandbox Code Playgroud)

nsurlrequest ios nsurlsession swift swift3

8
推荐指数
1
解决办法
1万
查看次数

Google Maps iOS反向地理编码

在将UILabel的文本设置为反向地理编码的地址时,Google Maps反向地理编码存在问题。UILabel在XIB中用作自定义信息窗口。我还有另一个自定义信息窗口,用于正常工作的其他数据,但是,当我尝试在反向地址解析回调/完成处理程序中设置标签的文本时,它不起作用。这是我到目前为止的代码,我已经尝试了多种方法,包括将其分配给变量,但是我什么都无法工作。

let infoWindow = NSBundle.mainBundle().loadNibNamed("InfoWindowCurrent", owner: self, options: nil)[0] as! InfoWindowCurrent
let geocoder = GMSGeocoder()
let coordinate = CLLocationCoordinate2DMake(Double(self.locLatitude)!, Double(self.locLongitude)!)

var currentAddress = String()

geocoder.reverseGeocodeCoordinate(coordinate) { response , error in
    if let address = response?.firstResult() {
        let lines = address.lines! as [String]

        currentAddress = lines.joinWithSeparator("\n")
    }
}

infoWindow.labelAddressStreet.text = currentAddress

return infoWindow
Run Code Online (Sandbox Code Playgroud)

我也尝试过这个:

let infoWindow = NSBundle.mainBundle().loadNibNamed("InfoWindowCurrent", owner: self, options: nil)[0] as! InfoWindowCurrent
let geocoder = GMSGeocoder()
let coordinate = CLLocationCoordinate2DMake(Double(self.locLatitude)!, Double(self.locLongitude)!)

geocoder.reverseGeocodeCoordinate(coordinate) { response , error in
    if …
Run Code Online (Sandbox Code Playgroud)

google-maps reverse-geocoding ios swift

5
推荐指数
2
解决办法
1万
查看次数

AVPlayerLayer 在 UIView 层中的位置

我正在使用 Swift 编写一个应用程序,以通过 HLS 查看监控摄像头。我有基本的设备列表工作,我能够转至实时视图并显示流,但是,我需要移动 AVPlayerLayer,但我无法弄清楚这一点。这是我当前的代码:

    let player = AVPlayer(URL: url!)
    let playerLayer = AVPlayerLayer(player: player)
    let view = UIView(frame: CGRectMake(0, 0, screenSize.width, screenSize.height))

    self.view.layer.borderWidth = 1
    self.view.layer.borderColor = UIColor(red:222/255.0, green:225/255.0, blue:227/255.0, alpha: 1.0).CGColor
    self.view.layer.addSublayer(playerLayer)

    playerLayer.frame = view.bounds
    player.play()
Run Code Online (Sandbox Code Playgroud)

我希望将 AVPlayerLayer 放置在顶部下方 50 点处,因为每个视图场景都有一个标题。

谢谢!

uiview http-live-streaming ios avplayerlayer swift

4
推荐指数
1
解决办法
7043
查看次数