微信支付回调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()")!

}

}

你可能感兴趣的:(微信支付回调onResp向其他页面传值)