美文网首页
微信支付回调onResp向其他页面传值

微信支付回调onResp向其他页面传值

作者: jadn | 来源:发表于2016-09-06 11:12 被阅读125次

AppDelegate.swift

if(resp.isKindOfClass(PayResp)){

if(resp.errCode==1){

//成功

let notification:NSNotification = NSNotification(name: "payNotification", object: "success")

NSNotificationCenter.defaultCenter().postNotification(notification)

}else{

//失败

let notification:NSNotification = NSNotification(name: "payNotification", object: "fail")

NSNotificationCenter.defaultCenter().postNotification(notification)

}

}

WebViewController.swift

/*这里先删除是避免重复监听*/

NSNotificationCenter.defaultCenter().removeObserver(self, name: "payNotification", object: nil)

NSNotificationCenter.defaultCenter().addObserver(self, selector: "getPayResult:", name: "payNotification", object: nil)

func getPayResult(notification:NSNotification) {

//println(notification.object)

if((notification.object?.isEqualToString("success")) == true){

println("支付成功")

self.webView.stringByEvaluatingJavaScriptFromString("orderOK()")!

}else{

println("支付失败")

self.webView.stringByEvaluatingJavaScriptFromString("orderNO()")!

}

}

相关文章

网友评论

      本文标题:微信支付回调onResp向其他页面传值

      本文链接:https://www.haomeiwen.com/subject/fwjdettx.html