ReactiveCocoa 4.0: - 无法映射NSURLSession.sharedSession()。rac_dataWithRequest

时间:2016-03-24 07:33:22

标签: ios swift2 reactive-cocoa

当我使用反应性可可网络服务请求时,我收到了警告。

  

调用'on(已启动:事件:失败:已完成:已中断:已终止:已处置:下一个:)的结果未使用:您是否忘记在生产者上调用start

代码:

    func callwebservice(dataDictionary:[String: String]? , urlString: String){
    print("******* dictionary = \(dataDictionary)")
    let boundary = "Boundary-\(NSUUID().UUIDString)"
    let request = NSMutableURLRequest(URL:NSURL(string: urlString)!);
    request.HTTPMethod = "POST"
    request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
    let body = NSMutableData();
    if dataDictionary != nil {
        for (key, value) in dataDictionary! {
            body.appendData(NSString(format:"--\(boundary)\r\n").dataUsingEncoding(NSUTF8StringEncoding)!)
            body.appendData(NSString(format:"Content-Disposition: form-data; name=\"\(key)\"\r\n\r\n").dataUsingEncoding(NSUTF8StringEncoding)!)
            body.appendData(NSString(format:"\(value)\r\n").dataUsingEncoding(NSUTF8StringEncoding)!)
            body.appendData(NSString(format:"--\(boundary)\r\n").dataUsingEncoding(NSUTF8StringEncoding)!)

        }
    }
    request.HTTPBody=body

    let requestType =  NSURLSession.sharedSession().rac_dataWithRequest(request)
    requestType.on(started: {
        print("Started")
        }, event: { event in
            print("Event: \(event)")
        }, failed: { error in
            print("Failed: \(error)")
        }, completed: {
            print("Completed")
        }, interrupted: {
            print("Interrupted")
        }, terminated: {
            print("Terminated")
        }, disposed: {
            print("Disposed")
        }, next: { value in
            print("Next: \(value)")
    })
}

enter image description here

1 个答案:

答案 0 :(得分:2)

您需要致电.start()以获取信号。现在它只是一个SignalProducer。 .start()电话后添加on(…)