https://developers.weixin.qq.com/doc/oplatform/Mobile_App/WeChat_Login/Login_via_Scan.html
// WeChatModule.h
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>
#import <WechatAuthSDK.h>
@interface WeChatModule : RCTEventEmitter<RCTBridgeModule, WechatAuthAPIDelegate>
@property (nonatomic, strong) WechatAuthSDK* wxAuthSdk;
@end
// WeChatModule.m
#import "WeChatModule.h"
@implementation WeChatModule
- (instancetype)init {
self = [super init];
if (self) {
self.wxAuthSdk = [[WechatAuthSDK alloc] init];
[self.wxAuthSdk setDelegate:self];
}
return self;
}
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(wxQRCodeLogin:(NSDictionary *)param :(RCTResponseSenderBlock)callback) {
NSString *appId = [param objectForKey:@"appId"];
NSString *nonceStr = [param objectForKey:@"nonceStr"];
NSString *timeStamp = [param objectForKey:@"timeStamp"];
NSString *scope = [param objectForKey:@"scope"];
NSString *signature = [param objectForKey:@"signature"];
NSString *schemeData = [param objectForKey:@"schemeData"];
NSLog(@"===delegate: %@", _wxAuthSdk.delegate);
[_wxAuthSdk StopAuth];
BOOL done = [_wxAuthSdk Auth:appId nonceStr:nonceStr timeStamp: timeStamp scope:scope signature:signature schemeData:schemeData];
callback(@[@(done)]);
}
- (void)onAuthGotQrcode:(UIImage *)image {
NSLog(@"===onAuthGotQrcode");
NSData *imageData = UIImagePNGRepresentation(image);
if (imageData == nil) {
imageData = UIImageJPEGRepresentation(image, 1);
}
[self sendEventWithName:@"onAuthGotQrcode" body:@{@"qrCode": imageData}];
}
//二维码被扫描
- (void)onQrcodeScanned {
NSLog(@"===onQrcodeScanned");
[self sendEventWithName:@"onQrcodeScanned" body:@{}];
}
//成功登录
- (void)onAuthFinish:(int)errCode AuthCode:(nullable NSString *)authCode {
NSLog(@"===onAuthFinish");
[self sendEventWithName:@"onAuthFinish" body:@{@"authCode": authCode, @"errCode": @(errCode)}];
}
- (NSArray<NSString *> *)supportedEvents
{
return @[@"onAuthGotQrcode", @"onQrcodeScanned", @"onAuthFinish"];
}
@end
运行后,打印了,xcode的output中打印了如下结果:
===delegate: <WeChatModule: 0x2813afae0>
---getWeChatLoginQRCode callback //js 代码里也在callback被执行时打印了
但是===onAuthGotQrcode一直没有被打印,也没有显示任何错误,请问有人知道是什么问题吗?
iOS 13.3,xcode14.2, WechatAuthSDK的sdkversion 2.0, "react-native-wechat-lib": "1.1.26"