微信支付点击左上角返回APP不走回调方法
//微信支付添加方法`
/**
* 此方法是由于系统版本更新而出现的方法 (支付宝 // NOTE: 9.0以后使用新API接口)
*/
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options{}
//和
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{}``- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{}
因此点击左上角返回时无法监听到
解决方法:
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
NSString * weixinPay = [[NSUserDefaults standardUserDefaults] objectForKey:@"weixinRechargePay"];
if ([weixinPay isEqualToString:@"recharge"]) {
//处理微信支付点击左上角返回
[[NSNotificationCenter defaultCenter] postNotificationName:@"weixinPayClickLiftCornerBack" object:nil];
[[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:@"weixinRechargePay"];
}
//角标清0
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
在applicationWillEnterForeground
方法里面发送通知,在调起微信支付的界面监听通知并进行订单查询操作,根据订单查询的结果进行下一步操作。
在发起支付方法里面[[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"weixinRechargePay"];
保存key值防止每次进入APP都发送订单查询的通知
执行顺序:
微信支付点击左上角返回APP 之后执行顺序 BackTrade_stateMsg:
然后到微信再点击返回APP:在查询订单方法里面 执行回调 backResp: 继续执行回调backCode:
点击右边返回APP: 在查询订单方法里面 执行回到backCode: