当其他配置没问题的时候,一定要检查UniversalLinks
[WXApi registerApp:WXAPPID universalLink:WXUniversalLinks];
UniversalLinks检查,仅测试环境使用,要求微信sdk>1.8.7
//在register之前打开log, 后续可以根据log排查问题
[WXApi startLogByLevel:WXLogLevelDetail logBlock:^(NSString *log) {
NSLog(@"WeChatSDK: %@", log);
}];
//务必在调用自检函数前注册
[WXApi registerApp:APP_ID universalLink:UNIVERSAL_LINK];
//调用自检函数
[WXApi checkUniversalLinkReady:^(WXULCheckStep step, WXCheckULStepResult* result) {
NSLog(@"%@, %u, %@, %@", @(step), result.success, result.errorInfo, result.suggestion);
}];
WXApiManager.h
#import <WXApi.h>
@protocol WXApiManagerDelegate <NSObject>
@end
@interface WXApiManager : NSObject<WXApiDelegate>
@property (nonatomic, assign) id<WXApiManagerDelegate> delegate;
+ (instancetype)sharedManager;
@end
WXApiManager.m
#import "WXApiManager.h"
@implementation WXApiManager
#pragma mark - LifeCycle
+ (instancetype)sharedManager {
static dispatch_once_t onceToken;
static WXApiManager *instance;
dispatch_once(&onceToken, ^{
instance = [[WXApiManager alloc] init];
});
return instance;
}
#pragma mark - WXApiDelegate
- (void)onResp:(BaseResp *)resp {
if([resp isKindOfClass:[PayResp class]]){
switch (resp.errCode) {
case WXSuccess:
NSLog(@"支付成功-PaySuccess,retcode = %d", resp.errCode);
break;
default:
NSLog(@"错误,retcode = %d, retstr = %@", resp.errCode,resp.errStr);
break;
}
}else {
}
}
- (void)onReq:(BaseReq *)req {
}
@end
设置代理方法
AppDelegate
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options{
// 微信的支付回调
if ([url.scheme isEqualToString:WXAPPID]){
return [WXApi handleOpenURL:url delegate:[WXApiManager sharedManager]];
}
return YES;
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray<id<UIUserActivityRestoring>> * __nullable restorableObjects))restorationHandler {
return [WXApi handleOpenUniversalLink:userActivity delegate:[WXApiManager sharedManager]];
}