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

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()")!

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容