iOS微信支付回调和iOS9系统左上角返回的冲突解决

首先,微信回调app的时候,APPdelegate中的几个方法的调用顺序:

1.跳转到微信后,直接点击左上角的返回小按钮,回到app:

applicationWillEnterForeground -> applicationDidBecomeActive

2.跳转到微信后,点击微信给出的tab按钮【取消】,或者直接支付完成后,点击【返回app】: 

applicationWillEnterForeground -> applicationDidBecomeActive -> openURL -> onResp

 

由此可见,想要完成支付的结果检测,必须在applicationDidBecomeActive和openURL中做文章。

1.需要一个全局的参数,来标识此时支付的状态。

  这里,用一个单例模式来保存支付的状态

//支付状态
@property (nonatomic, copy) NSString *State;

 在开始支付后,修改参数的值:

  单例.State = @"begin";

 

2.applicationDidBecomeActive中作出判断

//微信支付相关,解决左上角自带返回对微信回调的影响
    if ([[WXPayManager sharedWXPayManager].State isEqualToString:@"begin"]) {
        //支付流程结束
        [WXPayManager sharedWXPayManager].State = @"end";
        //
        if ([WXPayManager sharedWXPayManager].delegate
            && [[WXPayManager sharedWXPayManager].delegate respondsToSelector:@selector(managerDidRecvPayResponse:)]) {
            
            [[WXPayManager sharedWXPayManager].delegate managerDidRecvPayResponse:WXSuccess];
        }
    }

3.-(void) onResp:(BaseResp*)resp方法中,处理正常流程

//支付回调
    if([resp isKindOfClass:[PayResp class]]){
        //支付流程结束
        [WXPayManager sharedWXPayManager].State = @"end";
        //
        if ([WXPayManager sharedWXPayManager].delegate
            && [[WXPayManager sharedWXPayManager].delegate respondsToSelector:@selector(managerDidRecvPayResponse:)]) {
            
            PayResp *messageResp = (PayResp*)resp;
            [[WXPayManager sharedWXPayManager].delegate managerDidRecvPayResponse:messageResp.errCode];
        }
    }

  

   

  

posted @ 2017-02-17 14:58  Nuius  阅读(1107)  评论(0编辑  收藏  举报