使用Xcode 7.1,Swift 2.0
我在Swift上工作,目前正试图将PayU Money支付整合到iOS App(following this documentation)中。
我发现很难理解完成块,更多文档都是客观的C.有人可以帮我解决这个问题吗?
我不是编程方面的专家,所以只是想确保我在做写作。
这是我的代码:
import UIKit
class ViewController: UIViewController {
var paymentParamForPassing = PayUModelPaymentParams()
var webServiceResponse: PayUWebServiceResponse = PayUWebServiceResponse()
var createRequest: PayUCreateRequest = PayUCreateRequest()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
paymentParamForPassing.key = "0MQaQP"
paymentParamForPassing.transactionID = "Ywism0Q9XC88qvy";
paymentParamForPassing.amount = "10.0"
paymentParamForPassing.productInfo = "Nokia";
paymentParamForPassing.firstName = "Ram";
paymentParamForPassing.email = "email testsdk1.com";
paymentParamForPassing.userCredentials = "ra:ra";
paymentParamForPassing.phoneNumber = "1111111111";
paymentParamForPassing.SURL = "https://payu.herokuapp.com/ios_success";
paymentParamForPassing.FURL = "https://payu.herokuapp.com/ios_failure";
paymentParamForPassing.udf1 = "u1";
paymentParamForPassing.udf2 = "u2";
paymentParamForPassing.udf3 = "u3";
paymentParamForPassing.udf4 = "u4";
paymentParamForPassing.udf5 = "u5";
paymentParamForPassing.environment = ENVIRONMENT_MOBILETEST
paymentParamForPassing.offerKey = "offertest 1411";
paymentParamForPassing.hashes.paymentHash = "ade84bf6dd9da35d0aab50a5bf61d6272ab0fc488b361b65c66745054aacf1900e3c60b5022d2114bae7360174ebcb3cd7185a5d472e5c99701e5e7e1eccec34";
paymentParamForPassing.hashes.paymentRelatedDetailsHash = "915299224c80eff0eb2407b945a5087556292f58baca25fd05a0bceb6826aa9eb531810001dd4b4677dd928dd60d39eecf843b2189f213f9bb82c5a9483e3aac";
paymentParamForPassing.hashes.VASForMobileSDKHash = "5c0314c2781876f7e0a53676b0d08e1457dafe904d2d15d948626b57409538d51093eef4f15c792b1b9651be7b5659efdd45926e43a1145d68cea094687011ca";
paymentParamForPassing.hashes.deleteUserCardHash = "03e10e892005755f91061121036fb1b10f46202b4138d182f153c5de5c7fd44930ed94b32fac230e59bac1e4ca123aca3297e4b9d25024bf13237db9721fec1a";
paymentParamForPassing.hashes.offerHash = "1e99fdb59bd91c1a85624104c0fcfae34d7fcb850dd17a0b75e7efe49857d15fdefc47dd0d86ca34cbc3a8b580839aea6341a573e4e60dc1ddcf7ecc32bf9cae";
}
我在" createRequest ..."中收到以下警告:在paymentButtonPressed下面的行
我收到以下错误
无法 转换类型'的值(NSMutableURLRequest,String,NSError?) - > ()' 预期的参数类型 ' completionBlockForCreateRequestWithPaymentParam'!
@IBAction func paymentButtonPressed(sender: AnyObject) {
createRequest.createRequestWithPaymentParam(paymentParamForPassing, forPaymentType: PAYMENT_PG_PAYU_MONEY, withCompletionBlock: {(request: NSMutableURLRequest, postParam: String, error: NSError?) in
if error == nil {
print("Success")
}
else {
print("Fail")
}
})
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
任何人都知道我做错了什么?
答案 0 :(得分:0)
完成块的签名与PayUCreateRequest类中的声明不匹配。
您使用了以下代码:
withCompletionBlock:
{(request: NSMutableURLRequest, postParam: String, error: NSError?)
错误的类型为NSString。 您可以改用以下行。
withCompletionBlock:
{(request: NSMutableURLRequest, postParam: String, error: String)
我希望它可以帮到你。
答案 1 :(得分:0)
我为此工作过。你可以用它。这解决了错误。
createRequest.createRequestWithPaymentParam(paymentParamForPassing,forPaymentType: PAYMENT_PG_PAYU_MONNEY , withCompletionBlock: {(request, postParam , error) in
if error == nil {
print("Success")
}
else
{
print("Error data : \(error.debugDescription)")
print("Failure")
}
})