将Swift 2.3转换为Swift 3.0 – 错误,无法使用类型’的参数列表调用’dataTask’

将Swift 2.3转换为Swift 3.0 – 错误,无法使用类型’的参数列表调用’dataTask’,第1张

概述我正在尝试将我的一个项目从Swift 2.3转换为Swift 3.0,但有些原因我得到以下错误… Cannot invoke ‘dataTask’ with an argument list of type'(with: NSMutableURLRequest, completionHandler:(Data?, UIRLResponse?, NSError) -> Void)’ Overload 我正在尝试将我的一个项目从Swift 2.3转换为Swift 3.0,但有些原因我得到以下错误…

Cannot invoke ‘dataTask’ with an argument @R_419_6818@ of type'(with: NSMutableURLRequest,completionHandler:(Data?,UIRLResponse?,NSError) -> VoID)’

Overloads for ‘dataTask’ exist with these partially matching parameter @R_419_6818@s: (with: URLRequest,completionHandler:@escaPing(Data?,URLResponse?,Error?) -> VoID),(with: URL,completionHandler: @escaPing(Data?,Error?) -> VoID)

错误在下面的代码中显示在此行中…

let task = session.dataTask(with: request,completionHandler: { (responseData:Data?,response:URLResponse?,error:NSError?) -> VoID in

有什么建议吗?

以下是发生错误的函数的完整代码.

func verifyReceipt(_ transaction:SKPaymentTransaction?){        let receiptURL = Bundle.main.appStoreReceiptURL!        if let receipt = try? Data(contentsOf: receiptURL){            //Receipt exists            let requestContents = ["receipt-data" : receipt.base64EncodedString(options: NSData.Base64EnCodingOptions(rawValue: 0))]            //Perform request            do {                let requestData = try JsONSerialization.data(withJsONObject: requestContents,options: JsONSerialization.WritingOptions(rawValue: 0))                //Build URL Request                let storeURL = URL(string: "https://buy.itunes.apple.com/verifyReceipt")// production URL                //let storeURL = NSURL(string: "https:/sandBox.itunes.apple.com/verifyReceipt") // Testing URL                let request = NSMutableURLRequest(url: storeURL!)                request.httpMethod = "Post"                request.httpBody = requestData                let session = URLSession.shared                let task = session.dataTask(with: request,error:NSError?) -> VoID in                    //                    do {                        let Json = try JsONSerialization.JsonObject(with: responseData!,options: .mutableLeaves) as! NSDictionary                        print(Json)                        if (Json.object(forKey: "status") as! NSNumber) == 0 {                            //                            if let latest_receipt = Json["latest_receipt_info"]{                                self.valIDatePurchaseArray(latest_receipt as! NSArray)                            } else {                                let receipt_dict = Json["receipt"] as! NSDictionary                                if let purchases = receipt_dict["in_app"] as? NSArray{                                    self.valIDatePurchaseArray(purchases)                                }                            }                            if transaction != nil {                                SKPaymentQueue.default().finishTransaction(transaction!)                            }                            dispatchQueue.main.sync(execute: { () -> VoID in                                self.delegate?.managerDIDRestorePurchases()                            })                        } else {                            //DeBUG the receipt                            print(Json.object(forKey: "status") as! NSNumber)                        }                    } catch {                        print(error)                    }                })                task.resume()            } catch {                print(error)            }        } else {            //Receipt does not exist            print("No Receipt")        }    }
编译器需要URLRequest和Error
... var request = URLRequest(url: storeURL!) request.httpMethod = "Post" ... let task = session.dataTask(with: request,error:Error?) -> VoID in

我建议省略所有类型的注释

let task = session.dataTask(with: request,completionHandler: { (responseData,response,error) -> VoID in
总结

以上是内存溢出为你收集整理的将Swift 2.3转换为Swift 3.0 – 错误,无法使用类型’的参数列表调用’dataTask’全部内容,希望文章能够帮你解决将Swift 2.3转换为Swift 3.0 – 错误,无法使用类型’的参数列表调用’dataTask’所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1046738.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存