diff --git a/CHANGELOG.md b/CHANGELOG.md index 4412f321..077e1add 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 4.6.1 +* 修复 iOS 使用 thumbnail 字段分享的问题 + # 4.6.0 * Android SDK => 6.8.30 * 分享新增基础字段:thumbData diff --git a/ios/Classes/FluwxPlugin.m b/ios/Classes/FluwxPlugin.m index 67c618fa..28d9d486 100644 --- a/ios/Classes/FluwxPlugin.m +++ b/ios/Classes/FluwxPlugin.m @@ -4,6 +4,7 @@ #import #import #import +#import #import #import #import @@ -542,8 +543,7 @@ - (void)shareImage:(FlutterMethodCall *)call result:(FlutterResult)result { dispatch_async(dispatch_get_main_queue(), ^{ FlutterStandardTypedData *flutterThumbData = call.arguments[fluwxKeyThumbData]; NSData *thumbData = nil; - - if (flutterThumbData != nil){ + if (flutterThumbData != nil && ![flutterThumbData isKindOfClass:[NSNull class]]) { thumbData = flutterThumbData.data; } @@ -582,8 +582,7 @@ - (void)shareWebPage:(FlutterMethodCall *)call result:(FlutterResult)result { FlutterStandardTypedData *flutterThumbData = call.arguments[fluwxKeyThumbData]; NSData *thumbData = nil; - - if (flutterThumbData != nil){ + if (flutterThumbData != nil && ![flutterThumbData isKindOfClass:[NSNull class]]) { thumbData = flutterThumbData.data; } @@ -615,8 +614,7 @@ - (void)shareMusic:(FlutterMethodCall *)call result:(FlutterResult)result { dispatch_async(dispatch_get_main_queue(), ^{ FlutterStandardTypedData *flutterThumbData = call.arguments[fluwxKeyThumbData]; NSData *thumbData = nil; - - if (flutterThumbData != nil){ + if (flutterThumbData != nil && ![flutterThumbData isKindOfClass:[NSNull class]]) { thumbData = flutterThumbData.data; } @@ -650,12 +648,11 @@ - (void)shareVideo:(FlutterMethodCall *)call result:(FlutterResult)result { UIImage *thumbnailImage = [self getCommonThumbnail:call]; dispatch_async(dispatch_get_main_queue(), ^{ - NSNumber *scene = call.arguments[fluwxKeyScene]; + FlutterStandardTypedData *flutterThumbData = call.arguments[fluwxKeyThumbData]; NSData *thumbData = nil; - - if (flutterThumbData != nil){ + if (flutterThumbData != nil && ![flutterThumbData isKindOfClass:[NSNull class]]) { thumbData = flutterThumbData.data; } @@ -698,8 +695,7 @@ - (void)shareFile:(FlutterMethodCall *)call result:(FlutterResult)result { FlutterStandardTypedData *flutterThumbData = call.arguments[fluwxKeyThumbData]; NSData *thumbData = nil; - - if (flutterThumbData != nil){ + if (flutterThumbData != nil && ![flutterThumbData isKindOfClass:[NSNull class]]) { thumbData = flutterThumbData.data; } @@ -742,11 +738,9 @@ - (void)shareMiniProgram:(FlutterMethodCall *)call result:(FlutterResult)result } dispatch_async(dispatch_get_main_queue(), ^{ - FlutterStandardTypedData *flutterThumbData = call.arguments[fluwxKeyThumbData]; NSData *thumbData = nil; - - if (flutterThumbData != nil){ + if (flutterThumbData != nil && ![flutterThumbData isKindOfClass:[NSNull class]]) { thumbData = flutterThumbData.data; } @@ -1673,12 +1667,20 @@ - (WXMediaMessage *)messageWithTitle:(NSString *)title message.messageExt = messageExt; message.messageAction = action; message.mediaTagName = tagName; - message.thumbData = thumbData; - message.thumbDataHash = thumbDataHash; + if (thumbImage != nil) { + [message setThumbImage:thumbImage]; + // FIXME: setThumbImage still exists. Use the below code when it's not. + //NSData *data = UIImageJPEGRepresentation(thumbImage, 1.0); + //NSString *hash = [self sha256HashForData:data]; + //message.thumbData = data; + //message.thumbDataHash = hash; + } else { + message.thumbData = thumbData; + message.thumbDataHash = thumbDataHash; + } if(msgSignature != nil ){ message.msgSignature = msgSignature; } - [message setThumbImage:thumbImage]; return message; } @@ -1706,4 +1708,16 @@ -(NSString*)fetchWeChatAppId{ } return nil; } + +- (NSString *)sha256HashForData:(NSData *)data { + uint8_t hash[CC_SHA256_DIGEST_LENGTH]; + CC_SHA256(data.bytes, (CC_LONG)data.length, hash); + + NSMutableString *hashString = [NSMutableString stringWithCapacity:CC_SHA256_DIGEST_LENGTH * 2]; + for (int i = 0; i < CC_SHA256_DIGEST_LENGTH; i++) { + [hashString appendFormat:@"%02x", hash[i]]; + } + return [hashString copy]; +} + @end diff --git a/pubspec.yaml b/pubspec.yaml index 2f5c7a36..16e76949 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: fluwx description: The capability of implementing WeChat SDKs in Flutter. With Fluwx, developers can use WeChatSDK easily, such as sharing, payment, lanuch mini program and etc. -version: 4.6.0 +version: 4.6.1 homepage: https://github.com/OpenFlutter/fluwx environment: