Skip to content

Commit

Permalink
Fix thumbnail issues on iOS (#660)
Browse files Browse the repository at this point in the history
- Fixes #650
- Fixes #647
  • Loading branch information
JarvanMo authored Nov 1, 2024
2 parents abe7051 + f11aabb commit 00e9d65
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 4.6.1
* 修复 iOS 使用 thumbnail 字段分享的问题

# 4.6.0
* Android SDK => 6.8.30
* 分享新增基础字段:thumbData
Expand Down
48 changes: 31 additions & 17 deletions ios/Classes/FluwxPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#import <fluwx/ThumbnailHelper.h>
#import <fluwx/FluwxStringUtil.h>
#import <fluwx/NSStringWrapper.h>
#import <CommonCrypto/CommonDigest.h>
#import <WXApi.h>
#import <WXApiObject.h>
#import <WechatAuthSDK.h>
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 00e9d65

Please sign in to comment.