From 0be32445359a35559af0f3142ece091f99df4fd8 Mon Sep 17 00:00:00 2001 From: snowfox Date: Thu, 16 Feb 2023 18:10:04 +0800 Subject: [PATCH] :hammer:IOS support, Troubleshoot errors caused by compatibility problems with the old and new SDKS --- ios/WechatLib.mm | 39 ++++++++++++++++++++++++++++----------- package.json | 2 +- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/ios/WechatLib.mm b/ios/WechatLib.mm index 36d30ab..51e6160 100644 --- a/ios/WechatLib.mm +++ b/ios/WechatLib.mm @@ -12,8 +12,6 @@ #define NOT_REGISTERED (@"registerApp required.") #define INVOKE_FAILED (@"WeChat API invoke returns false.") -@implementation RCTWeChat - @synthesize bridge = _bridge; RCT_EXPORT_MODULE() @@ -231,7 +229,7 @@ RCT_EXPORT_METHOD(shareText:(NSDictionary *)data SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init]; req.bText = YES; req.text = data[@"text"]; - req.scene = [data[@"scene"] integerValue]; + req.scene = [data[@"scene"] intValue]; void ( ^ completion )( BOOL ); completion = ^( BOOL success ) { @@ -278,7 +276,7 @@ RCT_EXPORT_METHOD(shareFile:(NSDictionary *)data SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init]; req.bText = NO; req.message = message; - req.scene = [data[@"scene"] integerValue]; + req.scene = [data[@"scene"] intValue]; void ( ^ completion )( BOOL ); completion = ^( BOOL success ) { @@ -322,7 +320,7 @@ RCT_EXPORT_METHOD(shareImage:(NSDictionary *)data SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init]; req.bText = NO; req.message = message; - req.scene = [data[@"scene"] integerValue]; + req.scene = [data[@"scene"] intValue]; // [WXApi sendReq:req]; void ( ^ completion )( BOOL ); completion = ^( BOOL success ) @@ -367,7 +365,7 @@ RCT_EXPORT_METHOD(shareLocalImage:(NSDictionary *)data SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init]; req.bText = NO; req.message = message; - req.scene = [data[@"scene"] integerValue]; + req.scene = [data[@"scene"] intValue]; // [WXApi sendReq:req]; void ( ^ completion )( BOOL ); completion = ^( BOOL success ) @@ -401,7 +399,7 @@ RCT_EXPORT_METHOD(shareMusic:(NSDictionary *)data SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init]; req.bText = NO; req.message = message; - req.scene = [data[@"scene"] integerValue]; + req.scene = [data[@"scene"] intValue]; void ( ^ completion )( BOOL ); completion = ^( BOOL success ) { @@ -430,7 +428,7 @@ RCT_EXPORT_METHOD(shareVideo:(NSDictionary *)data SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init]; req.bText = NO; req.message = message; - req.scene = [data[@"scene"] integerValue]; + req.scene = [data[@"scene"] intValue]; void ( ^ completion )( BOOL ); completion = ^( BOOL success ) { @@ -458,7 +456,7 @@ RCT_EXPORT_METHOD(shareWebpage:(NSDictionary *)data SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init]; req.bText = NO; req.message = message; - req.scene = [data[@"scene"] integerValue]; + req.scene = [data[@"scene"] intValue]; void ( ^ completion )( BOOL ); completion = ^( BOOL success ) { @@ -483,7 +481,8 @@ RCT_EXPORT_METHOD(shareMiniProgram:(NSDictionary *)data object.hdImageData = [self compressImage: image toByte:131072]; } object.withShareTicket = data[@"withShareTicket"]; - object.miniProgramType = [data[@"miniProgramType"] integerValue]; + int miniProgramType = [data[@"miniProgramType"] integerValue]; + object.miniProgramType = [self integerToWXMiniProgramType:miniProgramType]; WXMediaMessage *message = [WXMediaMessage message]; message.title = data[@"title"]; message.description = data[@"description"]; @@ -534,7 +533,9 @@ RCT_EXPORT_METHOD(launchMiniProgram:(NSDictionary *)data // 拉起小程序页面的可带参路径,不填默认拉起小程序首页 launchMiniProgramReq.path = data[@"path"]; // 拉起小程序的类型 - launchMiniProgramReq.miniProgramType = [data[@"miniProgramType"] integerValue]; + int miniProgramType = [data[@"miniProgramType"] integerValue]; + launchMiniProgramReq.miniProgramType = [self integerToWXMiniProgramType:miniProgramType]; + // launchMiniProgramReq.miniProgramType = [data[@"miniProgramType"] integerValue]; void ( ^ completion )( BOOL ); completion = ^( BOOL success ) { @@ -644,5 +645,21 @@ RCT_EXPORT_METHOD(pay:(NSDictionary *)data } } +-(WXMiniProgramType) integerToWXMiniProgramType:(int)value { + WXMiniProgramType type = WXMiniProgramTypeRelease; + switch (value) { + case 0: + type = WXMiniProgramTypeRelease; + break; + case 1: + type = WXMiniProgramTypeTest; + break; + case 2: + type = WXMiniProgramTypePreview; + break; + } + return type; +} + @end diff --git a/package.json b/package.json index 3e4aa49..d3388aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-wechat-lib", - "version": "3.0.1", + "version": "3.0.2", "description": "test", "main": "lib/commonjs/index", "module": "lib/module/index",