From eeacf7382034578c6e3e63724d4510776dda369d Mon Sep 17 00:00:00 2001 From: Alex Li Date: Mon, 4 Nov 2024 17:31:05 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=94=A5=20Remove=20thumbnail=20and=20f?= =?UTF-8?q?ormat=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ios/Classes/FluwxDelegate.m | 3 +- ios/Classes/FluwxPlugin.m | 1070 ++++++++++++---------------- ios/Classes/FluwxStringUtil.m | 9 +- ios/Classes/ThumbnailHelper.h | 3 +- ios/Classes/ThumbnailHelper.m | 39 +- ios/Classes/public/FluwxDelegate.h | 1 + 6 files changed, 492 insertions(+), 633 deletions(-) diff --git a/ios/Classes/FluwxDelegate.m b/ios/Classes/FluwxDelegate.m index 5fd1ede2..6ecaba9b 100644 --- a/ios/Classes/FluwxDelegate.m +++ b/ios/Classes/FluwxDelegate.m @@ -20,9 +20,8 @@ + (instancetype)defaultManager { return instance; } -- (void) registerWxAPI:(NSString *)appId universalLink:(NSString *)universalLink { +- (void)registerWxAPI:(NSString *)appId universalLink:(NSString *)universalLink { [WXApi registerApp:appId universalLink:universalLink]; } - @end diff --git a/ios/Classes/FluwxPlugin.m b/ios/Classes/FluwxPlugin.m index 646e5ea9..c0369973 100644 --- a/ios/Classes/FluwxPlugin.m +++ b/ios/Classes/FluwxPlugin.m @@ -12,7 +12,6 @@ NSString *const fluwxKeyTitle = @"title"; NSString *const fluwxKeyImage = @ "image"; NSString *const fluwxKeyImageData = @ "imageData"; -NSString *const fluwxKeyThumbnail = @"thumbnail"; NSString *const fluwxKeyDescription = @"description"; NSString *const fluwxKeyMsgSignature = @"msgSignature"; NSString *const fluwxKeyThumbData = @"thumbData"; @@ -29,8 +28,6 @@ NSString *const fluwxKeySession = @"session"; NSString *const fluwxKeyFavorite = @"favorite"; -NSString *const fluwxKeyCompressThumbnail = @"compressThumbnail"; - NSString *const keySource = @"source"; NSString *const keySuffix = @"suffix"; @@ -39,7 +36,9 @@ NSUInteger defaultThumbnailSize = 32 * 1024; @interface FluwxPlugin() -@property (strong,nonatomic)NSString *extMsg; + +@property (strong, nonatomic)NSString *extMsg; + @end typedef void(^FluwxWXReqRunnable)(void); @@ -66,12 +65,11 @@ @implementation FluwxPlugin { NSObject *_fluwxRegistrar; - + (void)registerWithRegistrar:(NSObject *)registrar { _fluwxRegistrar = registrar; FlutterMethodChannel *channel = - [FlutterMethodChannel methodChannelWithName:@"com.jarvanmo/fluwx" - binaryMessenger:[registrar messenger]]; + [FlutterMethodChannel methodChannelWithName:@"com.jarvanmo/fluwx" + binaryMessenger:[registrar messenger]]; FluwxPlugin *instance = [[FluwxPlugin alloc] initWithChannel:channel]; [registrar addApplicationDelegate:instance]; [registrar addMethodCallDelegate:instance channel:channel]; @@ -96,7 +94,6 @@ - (instancetype)initWithChannel:(FlutterMethodChannel *)channel { } - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { - if ([@"registerApp" isEqualToString:call.method]) { [self registerApp:call result:result]; } else if ([@"isWeChatInstalled" isEqualToString:call.method]) { @@ -119,9 +116,9 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result [self handleautoDeductV2:call result:result]; } else if ([@"openBusinessView" isEqualToString:call.method]) { [self handleOpenBusinessView:call result:result]; - }else if([@"authByPhoneLogin" isEqualToString:call.method]){ + } else if ([@"authByPhoneLogin" isEqualToString:call.method]) { [self handleAuthByPhoneLogin:call result:result]; - }else if([@"getExtMsg" isEqualToString:call.method]){ + } else if ([@"getExtMsg" isEqualToString:call.method]) { [self handelGetExtMsgWithCall:call result:result]; } else if ([call.method hasPrefix:@"share"]) { [self handleShare:call result:result]; @@ -133,24 +130,23 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result [self handleOpenRankListCall:call result:result]; } else if ([@"openUrl" isEqualToString:call.method]) { [self handleOpenUrlCall:call result:result]; - } else if([@"openWeChatInvoice" isEqualToString:call.method]) { + } else if ([@"openWeChatInvoice" isEqualToString:call.method]) { [self openWeChatInvoice:call result:result]; - } else if([@"selfCheck" isEqualToString:call.method]) { - #ifndef __OPTIMIZE__ + } else if ([@"selfCheck" isEqualToString:call.method]) { +#ifndef __OPTIMIZE__ [WXApi checkUniversalLinkReady:^(WXULCheckStep step, WXCheckULStepResult* result) { NSString *log = [NSString stringWithFormat:@"%@, %u, %@, %@", @(step), result.success, result.errorInfo, result.suggestion]; [self logToFlutterWithDetail:log]; }]; - #endif +#endif result(nil); - } else if([@"attemptToResumeMsgFromWx" isEqualToString:call.method]){ + } else if ([@"attemptToResumeMsgFromWx" isEqualToString:call.method]) { if (_attemptToResumeMsgFromWxRunnable != nil) { _attemptToResumeMsgFromWxRunnable(); _attemptToResumeMsgFromWxRunnable = nil; - } - result(nil); - } - else if ([@"payWithFluwx" isEqualToString:call.method]) { + } + result(nil); + } else if ([@"payWithFluwx" isEqualToString:call.method]) { #ifndef NO_PAY [self handlePayment:call result:result]; #else @@ -162,21 +158,23 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result #else result(@NO); #endif - } - else { + } else { result(FlutterMethodNotImplemented); } } - (void)openWeChatInvoice:(FlutterMethodCall *)call result:(FlutterResult)result { - + NSString *appId = call.arguments[@"appId"]; - + if ([FluwxStringUtil isBlank:appId]) { - result([FlutterError errorWithCode:@"invalid app id" message:@"are you sure your app id is correct ? " details:appId]); + result([FlutterError + errorWithCode:@"invalid app id" + message:@"are you sure your app id is correct ? " + details:appId]); return; } - + WXChooseInvoiceReq *chooseInvoiceReq = [[WXChooseInvoiceReq alloc] init]; chooseInvoiceReq.appID = appId; chooseInvoiceReq.timeStamp = [[NSDate date] timeIntervalSince1970]; @@ -190,41 +188,47 @@ - (void)openWeChatInvoice:(FlutterMethodCall *)call result:(FlutterResult)result - (void)registerApp:(FlutterMethodCall *)call result:(FlutterResult)result { NSNumber* doOnIOS =call.arguments[@"iOS"]; - + if (![doOnIOS boolValue]) { result(@NO); return; } - + NSString *appId = call.arguments[@"appId"]; if ([FluwxStringUtil isBlank:appId]) { - result([FlutterError errorWithCode:@"invalid app id" message:@"are you sure your app id is correct ? " details:appId]); + result([FlutterError + errorWithCode:@"invalid app id" + message:@"are you sure your app id is correct ? " + details:appId]); return; } - + NSString *universalLink = call.arguments[@"universalLink"]; - + if ([FluwxStringUtil isBlank:universalLink]) { - result([FlutterError errorWithCode:@"invalid universal link" message:@"are you sure your universal link is correct ? " details:universalLink]); + result([FlutterError + errorWithCode:@"invalid universal link" + message:@"are you sure your universal link is correct ? " + details:universalLink]); return; } - + BOOL isWeChatRegistered = [WXApi registerApp:appId universalLink:universalLink]; - + // If registration fails, we can return immediately - if(!isWeChatRegistered){ + if (!isWeChatRegistered) { result(@(isWeChatRegistered)); _isRunning = NO; return; } - + // Otherwise, since WXApi is now registered successfully, // we can (and should) immediately handle the previously cached `app:openURL` event (if any) if (_cachedOpenUrlRequest != nil) { _cachedOpenUrlRequest(); _cachedOpenUrlRequest = nil; } - + // Set `_isRunning` after calling `_cachedOpenUrlRequest` to ensure that // the `onReq` triggered by this call to `_cachedOpenUrlRequest` will // be stored in `_attemptToResumeMsgFromWxRunnable` which can be obtained @@ -233,7 +237,7 @@ - (void)registerApp:(FlutterMethodCall *)call result:(FlutterResult)result { // At the same time, this also coincides with the approach on the Android side: // cold start events are cached and triggered through `attemptToResumeMsgFromWx` _isRunning = isWeChatRegistered; - + result(@(isWeChatRegistered)); } @@ -244,30 +248,27 @@ - (void)checkWeChatInstallation:(FlutterMethodCall *)call result:(FlutterResult) - (void)openWeChatCustomerServiceChat:(FlutterMethodCall *)call result:(FlutterResult)result { NSString *url = call.arguments[@"url"]; NSString *corpId = call.arguments[@"corpId"]; - - + WXOpenCustomerServiceReq *req = [[WXOpenCustomerServiceReq alloc] init]; - req.corpid = corpId; //企业ID - req.url = url; //客服URL + req.corpid = corpId; //企业ID + req.url = url; //客服URL return [WXApi sendReq:req completion:^(BOOL success) { result(@(success)); }]; } - (void)checkSupportOpenBusinessView:(FlutterMethodCall *)call result:(FlutterResult)result { - if(![WXApi isWXAppInstalled]){ + if (![WXApi isWXAppInstalled]) { result([FlutterError errorWithCode:@"WeChat Not Installed" message:@"Please install the WeChat first" details:nil]); - }else { + } else { result(@(true)); } } #ifndef NO_PAY - (void)handlePayment:(FlutterMethodCall *)call result:(FlutterResult)result { - - NSNumber *timestamp = call.arguments[@"timeStamp"]; - + NSString *partnerId = call.arguments[@"partnerId"]; NSString *prepayId = call.arguments[@"prepayId"]; NSString *packageValue = call.arguments[@"packageValue"]; @@ -275,7 +276,7 @@ - (void)handlePayment:(FlutterMethodCall *)call result:(FlutterResult)result { UInt32 timeStamp = [timestamp unsignedIntValue]; NSString *sign = call.arguments[@"sign"]; [FluwxDelegate defaultManager].extData = call.arguments[@"extData"]; - + NSString * appId = call.arguments[@"appId"]; PayReq *req = [[PayReq alloc] init]; req.openID = (appId == (id) [NSNull null]) ? nil : appId; @@ -285,16 +286,16 @@ - (void)handlePayment:(FlutterMethodCall *)call result:(FlutterResult)result { req.timeStamp = timeStamp; req.package = packageValue; req.sign = sign; - + [WXApi sendReq:req completion:^(BOOL done) { result(@(done)); }]; - + } - (void)handleHongKongWalletPayment:(FlutterMethodCall *)call result:(FlutterResult)result { NSString *partnerId = call.arguments[@"prepayId"]; - + WXOpenBusinessWebViewReq *req = [[WXOpenBusinessWebViewReq alloc] init]; req.businessType = 1; NSMutableDictionary *queryInfoDic = [NSMutableDictionary dictionary]; @@ -309,8 +310,8 @@ - (void)handleHongKongWalletPayment:(FlutterMethodCall *)call result:(FlutterRes - (void)handleLaunchMiniProgram:(FlutterMethodCall *)call result:(FlutterResult)result { NSString *userName = call.arguments[@"userName"]; NSString *path = call.arguments[@"path"]; -// WXMiniProgramType *miniProgramType = call.arguments[@"miniProgramType"]; - + //WXMiniProgramType *miniProgramType = call.arguments[@"miniProgramType"]; + NSNumber *typeInt = call.arguments[@"miniProgramType"]; WXMiniProgramType miniProgramType = WXMiniProgramTypeRelease; if ([typeInt isEqualToNumber:@1]) { @@ -318,13 +319,12 @@ - (void)handleLaunchMiniProgram:(FlutterMethodCall *)call result:(FlutterResult) } else if ([typeInt isEqualToNumber:@2]) { miniProgramType = WXMiniProgramTypePreview; } - - + WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object]; launchMiniProgramReq.userName = userName; launchMiniProgramReq.path = (path == (id) [NSNull null]) ? nil : path; launchMiniProgramReq.miniProgramType = miniProgramType; - + [WXApi sendReq:launchMiniProgramReq completion:^(BOOL done) { result(@(done)); }]; @@ -337,17 +337,17 @@ - (void)handleSubscribeWithCall:(FlutterMethodCall *)call result:(FlutterResult) NSNumber *scene = [params valueForKey:@"scene"]; NSString *templateId = [params valueForKey:@"templateId"]; NSString *reserved = [params valueForKey:@"reserved"]; - + WXSubscribeMsgReq *req = [WXSubscribeMsgReq new]; - #if __LP64__ - req.scene = [scene unsignedIntValue]; - #else - req.scene = [scene unsignedLongValue]; - #endif +#if __LP64__ + req.scene = [scene unsignedIntValue]; +#else + req.scene = [scene unsignedLongValue]; +#endif req.templateId = templateId; req.reserved = reserved; req.openID = appId; - + [WXApi sendReq:req completion:^(BOOL done) { result(@(done)); }]; @@ -367,7 +367,7 @@ - (void)handleAutoDeductWithCall:(FlutterMethodCall *)call result:(FlutterResult - (void)handleautoDeductV2:(FlutterMethodCall *)call result:(FlutterResult)result { NSMutableDictionary *paramsFromDart = call.arguments[@"queryInfo"]; -// [paramsFromDart removeObjectForKey:@"businessType"]; + // [paramsFromDart removeObjectForKey:@"businessType"]; WXOpenBusinessWebViewReq *req = [[WXOpenBusinessWebViewReq alloc] init]; NSNumber *businessType = call.arguments[@"businessType"]; req.businessType = [businessType unsignedIntValue]; @@ -379,7 +379,7 @@ - (void)handleautoDeductV2:(FlutterMethodCall *)call result:(FlutterResult)resul - (void)handleOpenBusinessView:(FlutterMethodCall *)call result:(FlutterResult)result { NSDictionary *params = call.arguments; - + WXOpenBusinessViewReq *req = [WXOpenBusinessViewReq object]; NSString *businessType = [params valueForKey:@"businessType"]; NSString *query = [params valueForKey:@"query"]; @@ -400,7 +400,10 @@ - (void)handelGetExtMsgWithCall:(FlutterMethodCall *)call result:(FlutterResult) // Deprecated since iOS 9 // See https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623073-application?language=objc // Use `application:openURL:options:` instead. -- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { +- (BOOL)application:(UIApplication *)application + openURL:(NSURL *)url + sourceApplication:(NSString *)sourceApplication + annotation:(id)annotation { // Since flutter has minimum iOS version requirement of 11.0, we don't need to change the implementation here. return [WXApi handleOpenURL:url delegate:self]; } @@ -415,27 +418,25 @@ - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceAppl // Available on iOS 9.0 and later // See https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623112-application?language=objc -- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { +- (BOOL)application:(UIApplication *)app + openURL:(NSURL *)url + options:(NSDictionary *)options { // ↓ previous solution -- according to document, this may fail if the WXApi hasn't registered yet. // return [WXApi handleOpenURL:url delegate:self]; - + if (_isRunning) { // registered -- directly handle open url request by WXApi return [WXApi handleOpenURL:url delegate:self]; - }else { + } else { // unregistered -- cache open url request and handle it once WXApi is registered __weak typeof(self) weakSelf = self; _cachedOpenUrlRequest = ^() { - __strong typeof(weakSelf) strongSelf = weakSelf; - [WXApi handleOpenURL:url delegate:strongSelf]; + __strong typeof(weakSelf) strongSelf = weakSelf; + [WXApi handleOpenURL:url delegate:strongSelf]; }; -// Let's hold this until the PR contributor send feedback. -// if ([url.absoluteString contains:[self fetchWeChatAppId]]){ -// return YES; -// } else { -// return NO; -// } - + // Let's hold this until the PR contributor send feedback. + //return [url.absoluteString contains:[self fetchWeChatAppId]]; + // simply return YES to indicate that we can handle open url request later return NO; } @@ -449,7 +450,7 @@ - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserAct #endif #ifdef SCENE_DELEGATE -- (void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivity API_AVAILABLE(ios(13.0)){ +- (void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivity API_AVAILABLE(ios(13.0)) { // TODO: (if need) cache userActivity and handle it once WXApi is registered [WXApi handleOpenUniversalLink:userActivity delegate:self]; } @@ -460,18 +461,18 @@ - (void)handleOpenUrlCall:(FlutterMethodCall *)call OpenWebviewReq *req = [[OpenWebviewReq alloc] init]; req.url = call.arguments[@"url"]; [WXApi sendReq:req - completion:^(BOOL success){ + completion:^(BOOL success) { result(@(success)); - }]; + }]; } - (void)handleOpenRankListCall:(FlutterMethodCall *)call result:(FlutterResult)result { OpenRankListReq *req = [[OpenRankListReq alloc] init]; [WXApi sendReq:req - completion:^(BOOL success){ + completion:^(BOOL success) { result(@(success)); - }]; + }]; } - (BOOL)handleOpenURL:(NSNotification *)aNotification { @@ -485,7 +486,7 @@ - (BOOL)handleOpenURL:(NSNotification *)aNotification { } - (void)logToFlutterWithDetail:(NSString *) detail { - if(_channel != nil){ + if (_channel != nil) { NSDictionary *result = @{ @"detail":detail }; @@ -514,300 +515,233 @@ - (void)handleShare:(FlutterMethodCall *)call result:(FlutterResult)result { - (void)shareText:(FlutterMethodCall *)call result:(FlutterResult)result { NSString *text = call.arguments[@"source"]; NSNumber *scene = call.arguments[fluwxKeyScene]; - + [self sendText:text InScene:[self intToWeChatScene:scene] completion:^(BOOL done) { result(@(done)); }]; } - (void)shareImage:(FlutterMethodCall *)call result:(FlutterResult)result { + NSNumber *scene = call.arguments[fluwxKeyScene]; + + NSDictionary *sourceImage = call.arguments[keySource]; + + FlutterStandardTypedData *flutterImageData = sourceImage[@"uint8List"]; + NSData *imageData = nil; + if (flutterImageData != nil) { + imageData = flutterImageData.data; + } + + NSString * imageDataHash = sourceImage[@"imgDataHash"]; + + FlutterStandardTypedData *flutterThumbData = call.arguments[fluwxKeyThumbData]; + NSData *thumbData = nil; + if (![flutterThumbData isKindOfClass:[NSNull class]]) { + thumbData = flutterThumbData.data; + } + dispatch_queue_t globalQueue = dispatch_get_global_queue(0, 0); dispatch_async(globalQueue, ^{ - - NSDictionary *sourceImage = call.arguments[keySource]; - - FlutterStandardTypedData *flutterImageData = sourceImage[@"uint8List"]; - NSData *imageData = nil; - - - if (flutterImageData != nil){ - imageData = flutterImageData.data; - } - - - NSString * imageDataHash = sourceImage[@"imgDataHash"]; - dispatch_async(dispatch_get_main_queue(), ^{ - - - FlutterStandardTypedData *flutterThumbData = call.arguments[fluwxKeyThumbData]; - NSData *thumbData = nil; - - - if (![flutterThumbData isKindOfClass:[NSNull class]]){ - thumbData = flutterThumbData.data; - } - - - NSNumber *scene = call.arguments[fluwxKeyScene]; [self sendImageData:imageData - ImgDataHash:imageDataHash - TagName:call.arguments[fluwxKeyMediaTagName] - MessageExt:call.arguments[fluwxKeyMessageExt] - Action:call.arguments[fluwxKeyMessageAction] - InScene:[self intToWeChatScene:scene] - title:call.arguments[fluwxKeyTitle] - description:call.arguments[fluwxKeyDescription] - MsgSignature:call.arguments[fluwxKeyMsgSignature] + ImgDataHash:imageDataHash + TagName:call.arguments[fluwxKeyMediaTagName] + MessageExt:call.arguments[fluwxKeyMessageExt] + Action:call.arguments[fluwxKeyMessageAction] + InScene:[self intToWeChatScene:scene] + title:call.arguments[fluwxKeyTitle] + description:call.arguments[fluwxKeyDescription] + MsgSignature:call.arguments[fluwxKeyMsgSignature] ThumbData:thumbData ThumbDataHash:call.arguments[fluwxKeyThumbDataHash] - completion:^(BOOL done) { - result(@(done)); - } - ]; - + completion:^(BOOL done) { + result(@(done)); + }]; }); - + }); } - (void)shareWebPage:(FlutterMethodCall *)call result:(FlutterResult)result { - + NSString *webPageUrl = call.arguments[@"webPage"]; + NSNumber *scene = call.arguments[fluwxKeyScene]; + + FlutterStandardTypedData *flutterThumbData = call.arguments[fluwxKeyThumbData]; + NSData *thumbData = nil; + if (![flutterThumbData isKindOfClass:[NSNull class]]) { + thumbData = flutterThumbData.data; + } + dispatch_queue_t globalQueue = dispatch_get_global_queue(0, 0); dispatch_async(globalQueue, ^{ - - UIImage *thumbnailImage = [self getCommonThumbnail:call]; - dispatch_async(dispatch_get_main_queue(), ^{ - NSString *webPageUrl = call.arguments[@"webPage"]; - NSNumber *scene = call.arguments[fluwxKeyScene]; - - FlutterStandardTypedData *flutterThumbData = call.arguments[fluwxKeyThumbData]; - NSData *thumbData = nil; - - - if (![flutterThumbData isKindOfClass:[NSNull class]]){ - thumbData = flutterThumbData.data; - } - [self sendLinkURL:webPageUrl - TagName:call.arguments[fluwxKeyMediaTagName] - Title:call.arguments[fluwxKeyTitle] - Description:call.arguments[fluwxKeyDescription] - ThumbImage:thumbnailImage - MessageExt:call.arguments[fluwxKeyMessageExt] - MessageAction:call.arguments[fluwxKeyMessageAction] - InScene:[self intToWeChatScene:scene] - MsgSignature:call.arguments[fluwxKeyMsgSignature] + TagName:call.arguments[fluwxKeyMediaTagName] + Title:call.arguments[fluwxKeyTitle] + Description:call.arguments[fluwxKeyDescription] + MessageExt:call.arguments[fluwxKeyMessageExt] + MessageAction:call.arguments[fluwxKeyMessageAction] + InScene:[self intToWeChatScene:scene] + MsgSignature:call.arguments[fluwxKeyMsgSignature] ThumbData:thumbData ThumbDataHash:call.arguments[fluwxKeyThumbDataHash] - completion:^(BOOL done) { - result(@(done)); - }]; + completion:^(BOOL done) { + result(@(done)); + }]; }); - + }); } - (void)shareMusic:(FlutterMethodCall *)call result:(FlutterResult)result { + NSNumber *scene = call.arguments[fluwxKeyScene]; + + FlutterStandardTypedData *flutterThumbData = call.arguments[fluwxKeyThumbData]; + NSData *thumbData = nil; + if (![flutterThumbData isKindOfClass:[NSNull class]]) { + thumbData = flutterThumbData.data; + } + dispatch_queue_t globalQueue = dispatch_get_global_queue(0, 0); dispatch_async(globalQueue, ^{ - - UIImage *thumbnailImage = [self getCommonThumbnail:call]; - dispatch_async(dispatch_get_main_queue(), ^{ - - FlutterStandardTypedData *flutterThumbData = call.arguments[fluwxKeyThumbData]; - NSData *thumbData = nil; - - - if (![flutterThumbData isKindOfClass:[NSNull class]]){ - thumbData = flutterThumbData.data; - } - NSNumber *scene = call.arguments[fluwxKeyScene]; [self sendMusicURL:call.arguments[@"musicUrl"] - dataURL:call.arguments[@"musicDataUrl"] - MusicLowBandUrl:call.arguments[@"musicLowBandUrl"] - MusicLowBandDataUrl:call.arguments[@"musicLowBandDataUrl"] - Title:call.arguments[fluwxKeyTitle] - Description:call.arguments[fluwxKeyDescription] - ThumbImage:thumbnailImage - MessageExt:call.arguments[fluwxKeyMessageExt] - MessageAction:call.arguments[fluwxKeyMessageAction] - TagName:call.arguments[fluwxKeyMediaTagName] - InScene:[self intToWeChatScene:scene] - MsgSignature:call.arguments[fluwxKeyMsgSignature] + dataURL:call.arguments[@"musicDataUrl"] + MusicLowBandUrl:call.arguments[@"musicLowBandUrl"] + MusicLowBandDataUrl:call.arguments[@"musicLowBandDataUrl"] + Title:call.arguments[fluwxKeyTitle] + Description:call.arguments[fluwxKeyDescription] + MessageExt:call.arguments[fluwxKeyMessageExt] + MessageAction:call.arguments[fluwxKeyMessageAction] + TagName:call.arguments[fluwxKeyMediaTagName] + InScene:[self intToWeChatScene:scene] + MsgSignature:call.arguments[fluwxKeyMsgSignature] ThumbData:thumbData ThumbDataHash:call.arguments[fluwxKeyThumbDataHash] - completion:^(BOOL done) { - result(@(done)); - } - ]; + completion:^(BOOL done) { + result(@(done)); + }]; }); }); } - (void)shareVideo:(FlutterMethodCall *)call result:(FlutterResult)result { + NSNumber *scene = call.arguments[fluwxKeyScene]; + + FlutterStandardTypedData *flutterThumbData = call.arguments[fluwxKeyThumbData]; + NSData *thumbData = nil; + if (![flutterThumbData isKindOfClass:[NSNull class]]) { + thumbData = flutterThumbData.data; + } + dispatch_queue_t globalQueue = dispatch_get_global_queue(0, 0); dispatch_async(globalQueue, ^{ - - 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 isKindOfClass:[NSNull class]]){ - thumbData = flutterThumbData.data; - } - [self sendVideoURL:call.arguments[@"videoUrl"] - VideoLowBandUrl:call.arguments[@"videoLowBandUrl"] - Title:call.arguments[fluwxKeyTitle] - Description:call.arguments[fluwxKeyDescription] - ThumbImage:thumbnailImage - MessageExt:call.arguments[fluwxKeyMessageExt] - MessageAction:call.arguments[fluwxKeyMessageAction] - TagName:call.arguments[fluwxKeyMediaTagName] - InScene:[self intToWeChatScene:scene] - MsgSignature:call.arguments[fluwxKeyMsgSignature] + VideoLowBandUrl:call.arguments[@"videoLowBandUrl"] + Title:call.arguments[fluwxKeyTitle] + Description:call.arguments[fluwxKeyDescription] + MessageExt:call.arguments[fluwxKeyMessageExt] + MessageAction:call.arguments[fluwxKeyMessageAction] + TagName:call.arguments[fluwxKeyMediaTagName] + InScene:[self intToWeChatScene:scene] + MsgSignature:call.arguments[fluwxKeyMsgSignature] ThumbData:thumbData ThumbDataHash:call.arguments[fluwxKeyThumbDataHash] - completion:^(BOOL done) { - result(@(done)); - }]; + completion:^(BOOL done) { + result(@(done)); + }]; }); }); } - (void)shareFile:(FlutterMethodCall *)call result:(FlutterResult)result { + NSDictionary *sourceFile = call.arguments[keySource]; + NSString *fileExtension; + NSString *suffix = sourceFile[keySuffix]; + fileExtension = suffix; + if ([suffix hasPrefix:@"."]) { + NSRange range = NSMakeRange(0, 1); + fileExtension = [suffix stringByReplacingCharactersInRange:range withString:@""]; + } + + NSData *data = [self getNsDataFromWeChatFile:sourceFile]; + NSNumber *scene = call.arguments[fluwxKeyScene]; + + FlutterStandardTypedData *flutterThumbData = call.arguments[fluwxKeyThumbData]; + NSData *thumbData = nil; + if (![flutterThumbData isKindOfClass:[NSNull class]]) { + thumbData = flutterThumbData.data; + } + dispatch_queue_t globalQueue = dispatch_get_global_queue(0, 0); dispatch_async(globalQueue, ^{ - NSDictionary *sourceFile = call.arguments[keySource]; - UIImage *thumbnailImage = [self getCommonThumbnail:call]; - NSString *fileExtension; - NSString *suffix = sourceFile[keySuffix]; - fileExtension = suffix; - if ([suffix hasPrefix:@"."]) { - NSRange range = NSMakeRange(0, 1); - fileExtension = [suffix stringByReplacingCharactersInRange:range withString:@""]; - } - - NSData *data = [self getNsDataFromWeChatFile:sourceFile]; - dispatch_async(dispatch_get_main_queue(), ^{ - NSNumber *scene = call.arguments[fluwxKeyScene]; - - FlutterStandardTypedData *flutterThumbData = call.arguments[fluwxKeyThumbData]; - NSData *thumbData = nil; - - - if (![flutterThumbData isKindOfClass:[NSNull class]]){ - thumbData = flutterThumbData.data; - } [self sendFileData:data - fileExtension:fileExtension - Title:call.arguments[fluwxKeyTitle] - Description:call.arguments[fluwxKeyDescription] - ThumbImage:thumbnailImage - InScene:[self intToWeChatScene:scene] - MsgSignature:call.arguments[fluwxKeyMsgSignature] + fileExtension:fileExtension + Title:call.arguments[fluwxKeyTitle] + Description:call.arguments[fluwxKeyDescription] + InScene:[self intToWeChatScene:scene] + MsgSignature:call.arguments[fluwxKeyMsgSignature] ThumbData:thumbData ThumbDataHash:call.arguments[fluwxKeyThumbDataHash] - completion:^(BOOL success) { - result(@(success)); - }]; + completion:^(BOOL success) { + result(@(success)); + }]; }); }); } - (void)shareMiniProgram:(FlutterMethodCall *)call result:(FlutterResult)result { + NSNumber *scene = call.arguments[fluwxKeyScene]; + + FlutterStandardTypedData *flutterThumbData = call.arguments[fluwxKeyThumbData]; + NSData *thumbData = nil; + if (![flutterThumbData isKindOfClass:[NSNull class]]) { + thumbData = flutterThumbData.data; + } + + FlutterStandardTypedData *hdImageDataPayload = call.arguments[@"hdImageData"]; + NSData *hdImageData = nil; + if (![hdImageDataPayload isKindOfClass:[NSNull class]]) { + hdImageData = hdImageDataPayload.data; + } + + NSNumber *typeInt = call.arguments[@"miniProgramType"]; + WXMiniProgramType miniProgramType = WXMiniProgramTypeRelease; + if ([typeInt isEqualToNumber:@1]) { + miniProgramType = WXMiniProgramTypeTest; + } else if ([typeInt isEqualToNumber:@2]) { + miniProgramType = WXMiniProgramTypePreview; + } dispatch_queue_t globalQueue = dispatch_get_global_queue(0, 0); dispatch_async(globalQueue, ^{ - - dispatch_async(dispatch_get_main_queue(), ^{ - - - FlutterStandardTypedData *flutterThumbData = call.arguments[fluwxKeyThumbData]; - FlutterStandardTypedData *hdImageDataPayload = call.arguments[@"hdImageData"]; - - NSData *thumbData = nil; - - NSData *hdImageData = nil; - - if (![flutterThumbData isKindOfClass:[NSNull class]]){ - thumbData = flutterThumbData.data; - } - - if (![hdImageDataPayload isKindOfClass:[NSNull class]]){ - hdImageData = hdImageDataPayload.data; - } - - - NSNumber *scene = call.arguments[fluwxKeyScene]; - - NSNumber *typeInt = call.arguments[@"miniProgramType"]; - WXMiniProgramType miniProgramType = WXMiniProgramTypeRelease; - if ([typeInt isEqualToNumber:@1]) { - miniProgramType = WXMiniProgramTypeTest; - } else if ([typeInt isEqualToNumber:@2]) { - miniProgramType = WXMiniProgramTypePreview; - } - [self sendMiniProgramWebpageUrl:call.arguments[@"webPageUrl"] - userName:call.arguments[@"userName"] - path:call.arguments[@"path"] - title:call.arguments[fluwxKeyTitle] - Description:call.arguments[fluwxKeyDescription] - withShareTicket:[call.arguments[@"withShareTicket"] boolValue] - miniProgramType:miniProgramType - MessageExt:call.arguments[fluwxKeyMessageExt] - MessageAction:call.arguments[fluwxKeyMessageAction] - TagName:call.arguments[fluwxKeyMediaTagName] - InScene:[self intToWeChatScene:scene] - MsgSignature:call.arguments[fluwxKeyMsgSignature] + userName:call.arguments[@"userName"] + path:call.arguments[@"path"] + title:call.arguments[fluwxKeyTitle] + Description:call.arguments[fluwxKeyDescription] + withShareTicket:[call.arguments[@"withShareTicket"] boolValue] + miniProgramType:miniProgramType + MessageExt:call.arguments[fluwxKeyMessageExt] + MessageAction:call.arguments[fluwxKeyMessageAction] + TagName:call.arguments[fluwxKeyMediaTagName] + InScene:[self intToWeChatScene:scene] + MsgSignature:call.arguments[fluwxKeyMsgSignature] HdImageData:hdImageData ThumbData:thumbData ThumbDataHash:call.arguments[fluwxKeyThumbDataHash] - completion:^(BOOL done) { - result(@(done)); - } - ]; - + completion:^(BOOL done) { + result(@(done)); + }]; }); - }); } - -- (UIImage *)getCommonThumbnail:(FlutterMethodCall *)call { - NSDictionary *thumbnail = call.arguments[fluwxKeyThumbnail]; - if (thumbnail == nil || thumbnail == (id) [NSNull null]) { - return nil; - } - - NSString *suffix = thumbnail[@"suffix"]; - NSNumber *compress = call.arguments[fluwxKeyCompressThumbnail]; - - NSData *thumbnailData = [self getNsDataFromWeChatFile:thumbnail]; - UIImage *thumbnailImage = [self getThumbnailFromNSData:thumbnailData size:defaultThumbnailSize isPNG:[self isPNG:suffix] compress:[compress boolValue]]; - return thumbnailImage; -} - -//enum ImageSchema { -// NETWORK, -// ASSET, -// FILE, -// BINARY, -//} - (NSData *)getNsDataFromWeChatFile:(NSDictionary *)weChatFile { NSNumber *schema = weChatFile[@"schema"]; - + if ([schema isEqualToNumber:@0]) { NSString *source = weChatFile[keySource]; NSURL *imageURL = [NSURL URLWithString:source]; @@ -829,10 +763,11 @@ - (NSData *)getNsDataFromWeChatFile:(NSDictionary *)weChatFile { - (UIImage *)getThumbnailFromNSData:(NSData *)data size:(NSUInteger)size isPNG:(BOOL)isPNG compress:(BOOL)compress { UIImage *uiImage = [UIImage imageWithData:data]; - if (compress) + if (compress) { return [ThumbnailHelper compressImage:uiImage toByte:size isPNG:isPNG]; - else + } else { return uiImage; + } } - (NSData *)getThumbnailDataFromNSData:(NSData *)data size:(NSUInteger)size compress:(BOOL)compress { @@ -851,7 +786,7 @@ - (NSString *)readFileFromAssets:(NSString *)imagePath { } else { key = [_fluwxRegistrar lookupKeyForAsset:array[0] fromPackage:array[1]]; } - + return [[NSBundle mainBundle] pathForResource:key ofType:nil]; } @@ -860,7 +795,7 @@ - (NSArray *)formatAssets:(NSString *)originPath { NSString *packageName = @""; NSString *pathWithoutSchema = originPath; NSInteger indexOfPackage = [pathWithoutSchema lastIndexOfString:@"?package="]; - + if (indexOfPackage != JavaNotFound) { path = [pathWithoutSchema substringFromIndex:0 toIndex:indexOfPackage]; NSInteger begin = indexOfPackage + [fluwxKeyPackage length]; @@ -868,7 +803,7 @@ - (NSArray *)formatAssets:(NSString *)originPath { } else { path = pathWithoutSchema; } - + return @[path, packageName]; } @@ -877,7 +812,7 @@ - (BOOL)isPNG:(NSString *)suffix { } - (enum WXScene)intToWeChatScene:(NSNumber *)value { -// enum WeChatScene { SESSION, TIMELINE, FAVORITE } + // enum WeChatScene { SESSION, TIMELINE, FAVORITE } if ([value isEqual:@0]) { return WXSceneSession; } else if ([value isEqual:@1]) { @@ -889,254 +824,214 @@ - (enum WXScene)intToWeChatScene:(NSNumber *)value { } } - - (void)managerDidRecvLaunchFromWXReq:(LaunchFromWXReq *)request { [FluwxDelegate defaultManager].extMsg = request.message.messageExt; -// LaunchFromWXReq *launchFromWXReq = (LaunchFromWXReq *)request; -// -// if (_isRunning) { -// [FluwxDelegate defaultManager].extMsg = request.message.messageExt; -// } else { -// __weak typeof(self) weakSelf = self; -// _initialWXReqRunnable = ^() { -// __strong typeof(weakSelf) strongSelf = weakSelf; -// [FluwxDelegate defaultManager].extMsg = request.message.messageExt -// }; -// } + // LaunchFromWXReq *launchFromWXReq = (LaunchFromWXReq *)request; + // + // if (_isRunning) { + // [FluwxDelegate defaultManager].extMsg = request.message.messageExt; + // } else { + // __weak typeof(self) weakSelf = self; + // _initialWXReqRunnable = ^() { + // __strong typeof(weakSelf) strongSelf = weakSelf; + // [FluwxDelegate defaultManager].extMsg = request.message.messageExt + // }; + // } } - - (void)onResp:(BaseResp *)resp { if ([resp isKindOfClass:[SendMessageToWXResp class]]) { - SendMessageToWXResp *messageResp = (SendMessageToWXResp *) resp; - - NSDictionary *result = @{ - description: messageResp.description == nil ? @"" : messageResp.description, - errStr: messageResp.errStr == nil ? @"" : messageResp.errStr, - errCode: @(messageResp.errCode), - fluwxType: @(messageResp.type), - country: messageResp.country == nil ? @"" : messageResp.country, - lang: messageResp.lang == nil ? @"" : messageResp.lang}; - if(_channel != nil){ + description: messageResp.description == nil ? @"" : messageResp.description, + errStr: messageResp.errStr == nil ? @"" : messageResp.errStr, + errCode: @(messageResp.errCode), + fluwxType: @(messageResp.type), + country: messageResp.country == nil ? @"" : messageResp.country, + lang: messageResp.lang == nil ? @"" : messageResp.lang}; + if (_channel != nil) { [_channel invokeMethod:@"onShareResponse" arguments:result]; } - - } else if ([resp isKindOfClass:[SendAuthResp class]]) { - SendAuthResp *authResp = (SendAuthResp *) resp; NSDictionary *result = @{ - description: authResp.description == nil ? @"" : authResp.description, - errStr: authResp.errStr == nil ? @"" : authResp.errStr, - errCode: @(authResp.errCode), - fluwxType: @(authResp.type), - country: authResp.country == nil ? @"" : authResp.country, - lang: authResp.lang == nil ? @"" : authResp.lang, - @"code": [FluwxStringUtil nilToEmpty:authResp.code], - @"state": [FluwxStringUtil nilToEmpty:authResp.state] - + description: authResp.description == nil ? @"" : authResp.description, + errStr: authResp.errStr == nil ? @"" : authResp.errStr, + errCode: @(authResp.errCode), + fluwxType: @(authResp.type), + country: authResp.country == nil ? @"" : authResp.country, + lang: authResp.lang == nil ? @"" : authResp.lang, + @"code": [FluwxStringUtil nilToEmpty:authResp.code], + @"state": [FluwxStringUtil nilToEmpty:authResp.state] + }; - - if(_channel != nil){ + + if (_channel != nil) { [_channel invokeMethod:@"onAuthResponse" arguments:result]; } - } else if ([resp isKindOfClass:[AddCardToWXCardPackageResp class]]) { - + // pass } else if ([resp isKindOfClass:[WXChooseCardResp class]]) { - + // pass } else if ([resp isKindOfClass:[WXChooseInvoiceResp class]]) { //TODO 处理发票返回,并回调Dart - + WXChooseInvoiceResp *chooseInvoiceResp = (WXChooseInvoiceResp *) resp; - - NSArray *array = chooseInvoiceResp.cardAry; - NSMutableArray *mutableArray = [NSMutableArray arrayWithCapacity:array.count]; - - for (int i = 0; i< array.count; i++) { WXInvoiceItem *item = array[i]; - - NSDictionary *dict = @{@"app_id":item.appID, @"encrypt_code":item.encryptCode, @"card_id":item.cardId}; [mutableArray addObject:dict]; } - + NSError *error = nil; - - NSData *jsonData = [NSJSONSerialization dataWithJSONObject:mutableArray options:NSJSONWritingPrettyPrinted error: &error]; - + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:mutableArray + options:NSJSONWritingPrettyPrinted + error: &error]; NSString *cardItemList = @""; - if ([jsonData length] && error == nil) { cardItemList = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; } - - NSDictionary *result = @{ - description: chooseInvoiceResp.description == nil ? @"" : chooseInvoiceResp.description, - errStr: chooseInvoiceResp.errStr == nil ? @"" : chooseInvoiceResp.errStr, - errCode: @(chooseInvoiceResp.errCode), - fluwxType: @(chooseInvoiceResp.type), - @"cardItemList":cardItemList - }; - - if(_channel != nil){ - + + NSDictionary *result = @{ + description: chooseInvoiceResp.description == nil ? @"" : chooseInvoiceResp.description, + errStr: chooseInvoiceResp.errStr == nil ? @"" : chooseInvoiceResp.errStr, + errCode: @(chooseInvoiceResp.errCode), + fluwxType: @(chooseInvoiceResp.type), + @"cardItemList":cardItemList + }; + + if (_channel != nil) { [_channel invokeMethod:@"onOpenWechatInvoiceResponse" arguments:result]; - } } else if ([resp isKindOfClass:[WXSubscribeMsgResp class]]) { - WXSubscribeMsgResp *subscribeMsgResp = (WXSubscribeMsgResp *) resp; NSMutableDictionary *result = [NSMutableDictionary dictionary]; NSString *openid = subscribeMsgResp.openId; - if(openid != nil && openid != NULL && ![openid isKindOfClass:[NSNull class]]){ - result[@"openid"] = openid; + if (openid != nil && openid != NULL && ![openid isKindOfClass:[NSNull class]]) { + result[@"openid"] = openid; } - + NSString *templateId = subscribeMsgResp.templateId; - if(templateId != nil && templateId != NULL && ![templateId isKindOfClass:[NSNull class]]){ - result[@"templateId"] = templateId; + if (templateId != nil && templateId != NULL && ![templateId isKindOfClass:[NSNull class]]) { + result[@"templateId"] = templateId; } - + NSString *action = subscribeMsgResp.action; - if(action != nil && action != NULL && ![action isKindOfClass:[NSNull class]]){ + if (action != nil && action != NULL && ![action isKindOfClass:[NSNull class]]) { result[@"action"] = action; } - + NSString *reserved = subscribeMsgResp.action; - if(reserved != nil && reserved != NULL && ![reserved isKindOfClass:[NSNull class]]){ - result[@"reserved"] = reserved; + if (reserved != nil && reserved != NULL && ![reserved isKindOfClass:[NSNull class]]) { + result[@"reserved"] = reserved; } - + UInt32 scene = subscribeMsgResp.scene; result[@"scene"] = @(scene); - if(_channel != nil){ + if (_channel != nil) { [_channel invokeMethod:@"onSubscribeMsgResp" arguments:result]; } - } else if ([resp isKindOfClass:[WXLaunchMiniProgramResp class]]) { - WXLaunchMiniProgramResp *miniProgramResp = (WXLaunchMiniProgramResp *) resp; - - NSDictionary *commonResult = @{ - description: miniProgramResp.description == nil ? @"" : miniProgramResp.description, - errStr: miniProgramResp.errStr == nil ? @"" : miniProgramResp.errStr, - errCode: @(miniProgramResp.errCode), - fluwxType: @(miniProgramResp.type), + description: miniProgramResp.description == nil ? @"" : miniProgramResp.description, + errStr: miniProgramResp.errStr == nil ? @"" : miniProgramResp.errStr, + errCode: @(miniProgramResp.errCode), + fluwxType: @(miniProgramResp.type), }; - + NSMutableDictionary *result = [NSMutableDictionary dictionaryWithDictionary:commonResult]; if (miniProgramResp.extMsg != nil) { result[@"extMsg"] = miniProgramResp.extMsg; } - - -// @"extMsg":miniProgramResp.extMsg == nil?@"":miniProgramResp.extMsg - - if(_channel != nil){ + if (_channel != nil) { [_channel invokeMethod:@"onLaunchMiniProgramResponse" arguments:result]; - } - } else if ([resp isKindOfClass:[WXInvoiceAuthInsertResp class]]) { - + // pass } else if ([resp isKindOfClass:[WXOpenBusinessWebViewResp class]]) { WXOpenBusinessWebViewResp *businessResp = (WXOpenBusinessWebViewResp *) resp; - NSDictionary *result = @{ - description: [FluwxStringUtil nilToEmpty:businessResp.description], - errStr: [FluwxStringUtil nilToEmpty:resp.errStr], - errCode: @(businessResp.errCode), - fluwxType: @(businessResp.type), - @"resultInfo": [FluwxStringUtil nilToEmpty:businessResp.result], - @"businessType": @(businessResp.businessType), + description: [FluwxStringUtil nilToEmpty:businessResp.description], + errStr: [FluwxStringUtil nilToEmpty:resp.errStr], + errCode: @(businessResp.errCode), + fluwxType: @(businessResp.type), + @"resultInfo": [FluwxStringUtil nilToEmpty:businessResp.result], + @"businessType": @(businessResp.businessType), }; - if(_channel != nil){ + if (_channel != nil) { [_channel invokeMethod:@"onWXOpenBusinessWebviewResponse" arguments:result]; } - - } else if ([resp isKindOfClass:[WXOpenCustomerServiceResp class]]) - { - + } else if ([resp isKindOfClass:[WXOpenCustomerServiceResp class]]) { WXOpenCustomerServiceResp *customerResp = (WXOpenCustomerServiceResp *) resp; NSDictionary *result = @{ - description: [FluwxStringUtil nilToEmpty:customerResp.description], - errStr: [FluwxStringUtil nilToEmpty:resp.errStr], - errCode: @(customerResp.errCode), - fluwxType: @(customerResp.type), - @"extMsg":[FluwxStringUtil nilToEmpty:customerResp.extMsg] + description: [FluwxStringUtil nilToEmpty:customerResp.description], + errStr: [FluwxStringUtil nilToEmpty:resp.errStr], + errCode: @(customerResp.errCode), + fluwxType: @(customerResp.type), + @"extMsg":[FluwxStringUtil nilToEmpty:customerResp.extMsg] }; - if(_channel != nil){ + if (_channel != nil) { [_channel invokeMethod:@"onWXOpenBusinessWebviewResponse" arguments:result]; } - - // 相关错误信息 - }else if ([resp isKindOfClass:[WXOpenBusinessViewResp class]]) - { - + // 相关错误信息 + } else if ([resp isKindOfClass:[WXOpenBusinessViewResp class]]) { WXOpenBusinessViewResp *openBusinessViewResp = (WXOpenBusinessViewResp *) resp; NSDictionary *result = @{ - description: [FluwxStringUtil nilToEmpty:openBusinessViewResp.description], - errStr: [FluwxStringUtil nilToEmpty:resp.errStr], - errCode: @(openBusinessViewResp.errCode), - @"businessType":openBusinessViewResp.businessType, - fluwxType: @(openBusinessViewResp.type), - @"extMsg":[FluwxStringUtil nilToEmpty:openBusinessViewResp.extMsg] + description: [FluwxStringUtil nilToEmpty:openBusinessViewResp.description], + errStr: [FluwxStringUtil nilToEmpty:resp.errStr], + errCode: @(openBusinessViewResp.errCode), + @"businessType":openBusinessViewResp.businessType, + fluwxType: @(openBusinessViewResp.type), + @"extMsg":[FluwxStringUtil nilToEmpty:openBusinessViewResp.extMsg] }; - if(_channel != nil){ + if (_channel != nil) { [_channel invokeMethod:@"onOpenBusinessViewResponse" arguments:result]; } - - // 相关错误信息 + // 相关错误信息 } #ifndef NO_PAY else if ([resp isKindOfClass:[WXPayInsuranceResp class]]) { - - } else if ([resp isKindOfClass:[PayResp class]]) { - + // pass + } else if ([resp isKindOfClass:[PayResp class]]) { PayResp *payResp = (PayResp *) resp; - NSDictionary *result = @{ - description: [FluwxStringUtil nilToEmpty:payResp.description], - errStr: [FluwxStringUtil nilToEmpty:resp.errStr], - errCode: @(payResp.errCode), - fluwxType: @(payResp.type), - @"extData": [FluwxStringUtil nilToEmpty:[FluwxDelegate defaultManager].extData], - @"returnKey": [FluwxStringUtil nilToEmpty:payResp.returnKey], + description: [FluwxStringUtil nilToEmpty:payResp.description], + errStr: [FluwxStringUtil nilToEmpty:resp.errStr], + errCode: @(payResp.errCode), + fluwxType: @(payResp.type), + @"extData": [FluwxStringUtil nilToEmpty:[FluwxDelegate defaultManager].extData], + @"returnKey": [FluwxStringUtil nilToEmpty:payResp.returnKey], }; [FluwxDelegate defaultManager].extData = nil; - if(_channel != nil){ + if (_channel != nil) { [_channel invokeMethod:@"onPayResponse" arguments:result]; } } else if ([resp isKindOfClass:[WXNontaxPayResp class]]) { - + // pass } #endif } - (void)onReq:(BaseReq *)req { if ([req isKindOfClass:[GetMessageFromWXReq class]]) { - + // pass } else if ([req isKindOfClass:[ShowMessageFromWXReq class]]) { // ShowMessageFromWXReq -- android spec ShowMessageFromWXReq *showMessageFromWXReq = (ShowMessageFromWXReq *) req; WXMediaMessage *wmm = showMessageFromWXReq.message; - + NSMutableDictionary *result = [NSMutableDictionary dictionary]; [result setValue:wmm.messageAction forKey:@"messageAction"]; [result setValue:wmm.messageExt forKey:@"extMsg"]; [result setValue:showMessageFromWXReq.lang forKey:@"lang"]; [result setValue:showMessageFromWXReq.country forKey:@"country"]; - + // Cache extMsg for later use (by calling 'getExtMsg') [FluwxDelegate defaultManager].extMsg= wmm.messageExt; - + if (_isRunning) { [_channel invokeMethod:@"onWXShowMessageFromWX" arguments:result]; } else { @@ -1146,21 +1041,20 @@ - (void)onReq:(BaseReq *)req { [strongSelf->_channel invokeMethod:@"onWXShowMessageFromWX" arguments:result]; }; } - } else if ([req isKindOfClass:[LaunchFromWXReq class]]) { // ShowMessageFromWXReq -- ios spec LaunchFromWXReq *launchFromWXReq = (LaunchFromWXReq *) req; WXMediaMessage *wmm = launchFromWXReq.message; - + NSMutableDictionary *result = [NSMutableDictionary dictionary]; [result setValue:wmm.messageAction forKey:@"messageAction"]; [result setValue:wmm.messageExt forKey:@"extMsg"]; [result setValue:launchFromWXReq.lang forKey:@"lang"]; [result setValue:launchFromWXReq.country forKey:@"country"]; - + // Cache extMsg for later use (by calling 'getExtMsg') [FluwxDelegate defaultManager].extMsg= wmm.messageExt; - + if (_isRunning) { [_channel invokeMethod:@"onWXLaunchFromWX" arguments:result]; } else { @@ -1171,19 +1065,16 @@ - (void)onReq:(BaseReq *)req { }; } } - } - (void)sendText:(NSString *)text InScene:(enum WXScene)scene completion:(void (^ __nullable)(BOOL success))completion { - SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init]; - req.scene = scene; - req.bText = YES; - req.text = text; - [WXApi sendReq:req - completion:completion]; + req.scene = scene; + req.bText = YES; + req.text = text; + [WXApi sendReq:req completion:completion]; } - (void)sendImageData:(NSData *)imageData @@ -1201,24 +1092,24 @@ - (void)sendImageData:(NSData *)imageData WXImageObject *ext = [WXImageObject object]; ext.imageData = imageData; ext.imgDataHash = (imgDataHash == (id) [NSNull null]) ? nil : imgDataHash; - + WXMediaMessage *message = [self messageWithTitle:(title == (id) [NSNull null]) ? nil : title - Description:(description == (id) [NSNull null]) ? nil : description - Object:ext - MessageExt:(messageExt == (id) [NSNull null]) ? nil : messageExt - MessageAction:(action == (id) [NSNull null]) ? nil : action - MediaTag:(tagName == (id) [NSNull null]) ? nil : tagName - MsgSignature:(msgSignature == (id) [NSNull null]) ? nil : msgSignature + Description:(description == (id) [NSNull null]) ? nil : description + Object:ext + MessageExt:(messageExt == (id) [NSNull null]) ? nil : messageExt + MessageAction:(action == (id) [NSNull null]) ? nil : action + MediaTag:(tagName == (id) [NSNull null]) ? nil : tagName + MsgSignature:(msgSignature == (id) [NSNull null]) ? nil : msgSignature ThumbData: thumbData ThumbDataHash:(thumbDataHash == (id) [NSNull null]) ? nil : thumbDataHash - + ];; - + SendMessageToWXReq *req = [self requestWithText:nil - OrMediaMessage:message - bText:NO - InScene:scene]; - + OrMediaMessage:message + bText:NO + InScene:scene]; + [WXApi sendReq:req completion:completion]; } @@ -1226,7 +1117,6 @@ - (void)sendLinkURL:(NSString *)urlString TagName:(NSString *)tagName Title:(NSString *)title Description:(NSString *)description - ThumbImage:(UIImage *)thumbImage MessageExt:(NSString *)messageExt MessageAction:(NSString *)messageAction InScene:(enum WXScene)scene @@ -1236,22 +1126,22 @@ - (void)sendLinkURL:(NSString *)urlString completion:(void (^ __nullable)(BOOL success))completion { WXWebpageObject *ext = [WXWebpageObject object]; ext.webpageUrl = urlString; - + WXMediaMessage *message = [self messageWithTitle:(title == (id) [NSNull null]) ? nil :title - Description:(description == (id) [NSNull null]) ? nil : description - Object:ext - MessageExt:(messageExt == (id) [NSNull null]) ? nil : messageExt - MessageAction:(messageAction == (id) [NSNull null]) ? nil : messageAction - MediaTag:(tagName == (id) [NSNull null]) ? nil : tagName - MsgSignature:(msgSignature == (id) [NSNull null]) ? nil : msgSignature + Description:(description == (id) [NSNull null]) ? nil : description + Object:ext + MessageExt:(messageExt == (id) [NSNull null]) ? nil : messageExt + MessageAction:(messageAction == (id) [NSNull null]) ? nil : messageAction + MediaTag:(tagName == (id) [NSNull null]) ? nil : tagName + MsgSignature:(msgSignature == (id) [NSNull null]) ? nil : msgSignature ThumbData: thumbData ThumbDataHash:(thumbDataHash == (id) [NSNull null]) ? nil : thumbDataHash ]; - + SendMessageToWXReq *req = [self requestWithText:nil - OrMediaMessage:message - bText:NO - InScene:scene]; + OrMediaMessage:message + bText:NO + InScene:scene]; [WXApi sendReq:req completion:completion]; } @@ -1261,7 +1151,6 @@ - (void)sendMusicURL:(NSString *)musicURL MusicLowBandDataUrl:(NSString *)musicLowBandDataUrl Title:(NSString *)title Description:(NSString *)description - ThumbImage:(UIImage *)thumbImage MessageExt:(NSString *)messageExt MessageAction:(NSString *)messageAction TagName:(NSString *)tagName @@ -1271,7 +1160,7 @@ - (void)sendMusicURL:(NSString *)musicURL ThumbDataHash:(NSString*)thumbDataHash completion:(void (^ __nullable)(BOOL success))completion { WXMusicObject *ext = [WXMusicObject object]; - + if ([FluwxStringUtil isBlank:musicURL]) { ext.musicLowBandUrl = musicLowBandUrl; ext.musicLowBandDataUrl = (musicLowBandDataUrl == (id) [NSNull null]) ? nil : musicLowBandDataUrl; @@ -1279,24 +1168,24 @@ - (void)sendMusicURL:(NSString *)musicURL ext.musicUrl = musicURL; ext.musicDataUrl = (dataURL == (id) [NSNull null]) ? nil : dataURL; } - - + + WXMediaMessage *message = [self messageWithTitle:(title == (id) [NSNull null]) ? nil : title - Description:description - Object:ext - MessageExt:(messageExt == (id) [NSNull null]) ? nil : messageExt - MessageAction:(messageAction == (id) [NSNull null]) ? nil : messageAction - MediaTag:(tagName == (id) [NSNull null]) ? nil : tagName - MsgSignature:(msgSignature == (id) [NSNull null]) ? nil : msgSignature + Description:description + Object:ext + MessageExt:(messageExt == (id) [NSNull null]) ? nil : messageExt + MessageAction:(messageAction == (id) [NSNull null]) ? nil : messageAction + MediaTag:(tagName == (id) [NSNull null]) ? nil : tagName + MsgSignature:(msgSignature == (id) [NSNull null]) ? nil : msgSignature ThumbData: thumbData ThumbDataHash:(thumbDataHash == (id) [NSNull null]) ? nil : thumbDataHash ]; - + SendMessageToWXReq *req = [self requestWithText:nil - OrMediaMessage:message - bText:NO - InScene:scene]; - + OrMediaMessage:message + bText:NO + InScene:scene]; + [WXApi sendReq:req completion:completion]; } @@ -1304,7 +1193,6 @@ - (void)sendVideoURL:(NSString *)videoURL VideoLowBandUrl:(NSString *)videoLowBandUrl Title:(NSString *)title Description:(NSString *)description - ThumbImage:(UIImage *)thumbImage MessageExt:(NSString *)messageExt MessageAction:(NSString *)messageAction TagName:(NSString *)tagName @@ -1319,8 +1207,9 @@ - (void)sendVideoURL:(NSString *)videoURL message.messageExt = (messageExt == (id) [NSNull null]) ? nil : messageExt; message.messageAction = (messageAction == (id) [NSNull null]) ? nil : messageAction; message.mediaTagName = (tagName == (id) [NSNull null]) ? nil : tagName; - [message setThumbImage:thumbImage]; - + message.thumbData = (thumbData == (id) [NSNull null]) ? nil : thumbData; + message.thumbDataHash = (thumbDataHash == (id) [NSNull null]) ? nil : thumbDataHash; + WXVideoObject *ext = [WXVideoObject object]; if ([FluwxStringUtil isBlank:videoURL]) { ext.videoLowBandUrl = videoLowBandUrl; @@ -1328,38 +1217,31 @@ - (void)sendVideoURL:(NSString *)videoURL ext.videoUrl = videoURL; } message.mediaObject = ext; - - SendMessageToWXReq *req = [self requestWithText:nil - OrMediaMessage:message - bText:NO - InScene:scene]; + + SendMessageToWXReq *req = [self requestWithText:nil OrMediaMessage:message bText:NO InScene:scene]; [WXApi sendReq:req completion:completion]; } - (void)sendEmotionData:(NSData *)emotionData - ThumbImage:(UIImage *)thumbImage InScene:(enum WXScene)scene MsgSignature:(NSString *)msgSignature ThumbData:(NSData *)thumbData ThumbDataHash:(NSString*)thumbDataHash completion:(void (^ __nullable)(BOOL success))completion { WXMediaMessage *message = [WXMediaMessage message]; - [message setThumbImage:thumbImage]; - + message.thumbData = (thumbData == (id) [NSNull null]) ? nil : thumbData; + message.thumbDataHash = (thumbDataHash == (id) [NSNull null]) ? nil : thumbDataHash; + WXEmoticonObject *ext = [WXEmoticonObject object]; ext.emoticonData = emotionData; - message.mediaObject = ext; - + NSString *signature = (msgSignature == (id) [NSNull null]) ? nil : msgSignature; if (signature != nil) { message.msgSignature = signature; } - - SendMessageToWXReq *req = [self requestWithText:nil - OrMediaMessage:message - bText:NO - InScene:scene]; + + SendMessageToWXReq *req = [self requestWithText:nil OrMediaMessage:message bText:NO InScene:scene]; [WXApi sendReq:req completion:completion]; } @@ -1367,7 +1249,6 @@ - (void)sendFileData:(NSData *)fileData fileExtension:(NSString *)extension Title:(NSString *)title Description:(NSString *)description - ThumbImage:(UIImage *)thumbImage InScene:(enum WXScene)scene MsgSignature:(NSString *)msgSignature ThumbData:(NSData *)thumbData @@ -1376,23 +1257,20 @@ - (void)sendFileData:(NSData *)fileData WXMediaMessage *message = [WXMediaMessage message]; message.title = title; message.description = description; - [message setThumbImage:thumbImage]; - + message.thumbData = (thumbData == (id) [NSNull null]) ? nil : thumbData; + message.thumbDataHash = (thumbDataHash == (id) [NSNull null]) ? nil : thumbDataHash; + WXFileObject *ext = [WXFileObject object]; ext.fileExtension = extension; ext.fileData = fileData; - message.mediaObject = ext; - + NSString *signature = (msgSignature == (id) [NSNull null]) ? nil : msgSignature; if (signature != nil) { message.msgSignature = signature; } - - SendMessageToWXReq *req = [self requestWithText:nil - OrMediaMessage:message - bText:NO - InScene:scene]; + + SendMessageToWXReq *req = [self requestWithText:nil OrMediaMessage:message bText:NO InScene:scene]; [WXApi sendReq:req completion:completion]; } @@ -1416,30 +1294,22 @@ - (void)sendMiniProgramWebpageUrl:(NSString *)webpageUrl ext.webpageUrl = (webpageUrl == (id) [NSNull null]) ? nil : webpageUrl; ext.userName = (userName == (id) [NSNull null]) ? nil : userName; ext.path = (path == (id) [NSNull null]) ? nil : path; - ext.withShareTicket = withShareTicket; - ext.hdImageData = hdImageData; - ext.miniProgramType = programType; - + WXMediaMessage *message = [self messageWithTitle:(title == (id) [NSNull null]) ? nil : title - Description:(description == (id) [NSNull null]) ? nil : description - Object:ext - MessageExt:(messageExt == (id) [NSNull null]) ? nil : messageExt - MessageAction:(messageAction == (id) [NSNull null]) ? nil : messageAction - MediaTag:(tagName == (id) [NSNull null]) ? nil : tagName - MsgSignature:(msgSignature == (id) [NSNull null]) ? nil : msgSignature - ThumbData: thumbData + Description:(description == (id) [NSNull null]) ? nil : description + Object:ext + MessageExt:(messageExt == (id) [NSNull null]) ? nil : messageExt + MessageAction:(messageAction == (id) [NSNull null]) ? nil : messageAction + MediaTag:(tagName == (id) [NSNull null]) ? nil : tagName + MsgSignature:(msgSignature == (id) [NSNull null]) ? nil : msgSignature + ThumbData:(thumbData == (id) [NSNull null] ? nil : thumbData) ThumbDataHash:(thumbDataHash == (id) [NSNull null]) ? nil : thumbDataHash - ]; - - SendMessageToWXReq *req = [self requestWithText:nil - OrMediaMessage:message - bText:NO - InScene:scene]; - + + SendMessageToWXReq *req = [self requestWithText:nil OrMediaMessage:message bText:NO InScene:scene]; [WXApi sendReq:req completion:completion]; } @@ -1450,7 +1320,6 @@ - (void)sendAppContentData:(NSData *)data Description:(NSString *)description MessageExt:(NSString *)messageExt MessageAction:(NSString *)action - ThumbImage:(UIImage *)thumbImage InScene:(enum WXScene)scene MsgSignature:(NSString *)msgSignature ThumbData:(NSData *)thumbData @@ -1460,27 +1329,24 @@ - (void)sendAppContentData:(NSData *)data ext.extInfo = info; ext.url = url; ext.fileData = data; - + WXMediaMessage *message = [self messageWithTitle:title - Description:description - Object:ext - MessageExt:messageExt - MessageAction:action - MediaTag:nil - MsgSignature:(msgSignature == (id) [NSNull null]) ? nil : msgSignature - ThumbData: thumbData + Description:description + Object:ext + MessageExt:messageExt + MessageAction:action + MediaTag:nil + MsgSignature:(msgSignature == (id) [NSNull null]) ? nil : msgSignature + ThumbData:(thumbData == (id) [NSNull null]) ? nil : thumbData ThumbDataHash:(thumbDataHash == (id) [NSNull null]) ? nil : thumbDataHash ]; - - SendMessageToWXReq *req = [self requestWithText:nil - OrMediaMessage:message - bText:NO - InScene:scene]; + + SendMessageToWXReq *req = [self requestWithText:nil OrMediaMessage:message bText:NO InScene:scene]; [WXApi sendReq:req completion:completion]; - } -- (void)addCardsToCardPackage:(NSArray *)cardIds cardExts:(NSArray *)cardExts +- (void)addCardsToCardPackage:(NSArray *)cardIds + cardExts:(NSArray *)cardExts completion:(void (^ __nullable)(BOOL success))completion { NSMutableArray *cardItems = [NSMutableArray array]; for (NSString *cardId in cardIds) { @@ -1489,13 +1355,13 @@ - (void)addCardsToCardPackage:(NSArray *)cardIds cardExts:(NSArray *)cardExts item.appID = @"wxf8b4f85f3a794e77"; [cardItems addObject:item]; } - + for (NSInteger index = 0; index < cardItems.count; index++) { WXCardItem *item = cardItems[index]; NSString *ext = cardExts[index]; item.extMsg = ext; } - + AddCardToWXCardPackageReq *req = [[AddCardToWXCardPackageReq alloc] init]; req.cardAry = cardItems; [WXApi sendReq:req completion:completion]; @@ -1514,10 +1380,8 @@ - (void)chooseCard:(NSString *)appid chooseCardReq.signType = signType; chooseCardReq.timeStamp = timestamp; [WXApi sendReq:chooseCardReq completion:completion]; - } - - (void)sendAuthRequestScope:(NSString *)scope State:(NSString *)state OpenID:(NSString *)openID @@ -1527,8 +1391,7 @@ - (void)sendAuthRequestScope:(NSString *)scope req.scope = scope; // @"post_timeline,sns" req.state = state; req.openID = openID; - - + return [WXApi sendAuthReq:req viewController:viewController delegate:self @@ -1546,9 +1409,9 @@ - (void)sendAuthRequestScope:(NSString *)scope req.state = state; req.openID = openID; req.nonautomatic = nonAutomatic; - + [WXApi sendReq:req completion:completion]; - + } @@ -1570,17 +1433,17 @@ - (void)chooseInvoice:(NSString *)appid chooseInvoiceReq.cardSign = cardSign; chooseInvoiceReq.nonceStr = nonceStr; chooseInvoiceReq.signType = signType; -// chooseCardReq.cardType = @"INVOICE"; + // chooseCardReq.cardType = @"INVOICE"; chooseInvoiceReq.timeStamp = timestamp; -// chooseCardReq.canMultiSelect = 1; + // chooseCardReq.canMultiSelect = 1; [WXApi sendReq:chooseInvoiceReq completion:completion]; } - (void)openCustomerService:(NSString *)url CorpId:(NSString *)corpId completion:(void (^)(BOOL))completion { WXOpenCustomerServiceReq *req = [[WXOpenCustomerServiceReq alloc] init]; - req.corpid = corpId; //企业ID - req.url = url; //客服URL + req.corpid = corpId; //企业ID + req.url = url; //客服URL [WXApi sendReq:req completion:completion]; } @@ -1596,14 +1459,14 @@ - (void)handleAuthByPhoneLogin:(FlutterMethodCall *)call result:(FlutterResult)r - (void)handleAuth:(FlutterMethodCall *)call result:(FlutterResult)result { NSString *openId = call.arguments[@"openId"]; - + [self sendAuthRequestScope:call.arguments[@"scope"] - State:(call.arguments[@"state"] == (id) [NSNull null]) ? nil : call.arguments[@"state"] - OpenID:(openId == (id) [NSNull null]) ? nil : openId - NonAutomatic:[call.arguments[@"nonAutomatic"] boolValue] - completion:^(BOOL done) { - result(@(done)); - }]; + State:(call.arguments[@"state"] == (id) [NSNull null]) ? nil : call.arguments[@"state"] + OpenID:(openId == (id) [NSNull null]) ? nil : openId + NonAutomatic:[call.arguments[@"nonAutomatic"] boolValue] + completion:^(BOOL done) { + result(@(done)); + }]; } - (void)authByQRCode:(FlutterMethodCall *)call result:(FlutterResult)result { @@ -1613,7 +1476,7 @@ - (void)authByQRCode:(FlutterMethodCall *)call result:(FlutterResult)result { NSString *timeStamp = call.arguments[@"timeStamp"]; NSString *signature = call.arguments[@"signature"]; NSString *schemeData = (call.arguments[@"schemeData"] == (id) [NSNull null]) ? nil : call.arguments[@"schemeData"]; - + BOOL done = [_qrauth Auth:appId nonceStr:nonceStr timeStamp:timeStamp scope:scope signature:signature schemeData:schemeData]; result(@(done)); } @@ -1624,19 +1487,19 @@ - (void)stopAuthByQRCode:(FlutterMethodCall *)call result:(FlutterResult)result } - (void)onQrcodeScanned { - if(_channel != nil){ - [_channel invokeMethod:@"onQRCodeScanned" arguments:@{@"errCode": @0}]; + if (_channel != nil) { + [_channel invokeMethod:@"onQRCodeScanned" arguments:@{@"errCode": @0}]; } } - (void)onAuthGotQrcode:(UIImage *)image { NSData *imageData = UIImagePNGRepresentation(image); -// if (imageData == nil) { -// imageData = UIImageJPEGRepresentation(image, 1); -// } - if(_channel != nil){ - [_channel invokeMethod:@"onAuthGotQRCode" arguments:@{@"errCode": @0, @"qrCode": imageData}]; - } + // if (imageData == nil) { + // imageData = UIImageJPEGRepresentation(image, 1); + // } + if (_channel != nil) { + [_channel invokeMethod:@"onAuthGotQRCode" arguments:@{@"errCode": @0, @"qrCode": imageData}]; + } } - (void)onAuthFinish:(int)errCode AuthCode:(nullable NSString *)authCode { @@ -1645,8 +1508,8 @@ - (void)onAuthFinish:(int)errCode AuthCode:(nullable NSString *)authCode { if (authCode != nil) { result[@"authCode"] = authCode; } - if(_channel != nil){ - [_channel invokeMethod:@"onAuthByQRCodeFinished" arguments:result]; + if (_channel != nil) { + [_channel invokeMethod:@"onAuthByQRCodeFinished" arguments:result]; } } @@ -1658,8 +1521,7 @@ - (WXMediaMessage *)messageWithTitle:(NSString *)title MediaTag:(NSString *)tagName MsgSignature:(NSString *)msgSignature ThumbData:(NSData *)thumbData - ThumbDataHash:(NSString*)thumbDataHash -{ + ThumbDataHash:(NSString*)thumbDataHash { WXMediaMessage *message = [WXMediaMessage message]; message.title = title; message.description = description; @@ -1669,7 +1531,7 @@ - (WXMediaMessage *)messageWithTitle:(NSString *)title message.mediaTagName = tagName; message.thumbData = thumbData; message.thumbDataHash = thumbDataHash; - if(msgSignature != nil ){ + if (msgSignature != nil) { message.msgSignature = msgSignature; } return message; @@ -1682,21 +1544,23 @@ - (SendMessageToWXReq *)requestWithText:(NSString *)text SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init]; req.bText = bText; req.scene = scene; - if (bText) + if (bText) { req.text = text; - else + } else { req.message = message; + } return req; } --(NSString*)fetchWeChatAppId{ +- (NSString*)fetchWeChatAppId { NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary]; NSArray* types = infoDic[@"CFBundleURLTypes"]; - for(NSDictionary* dic in types){ - if([@"weixin" isEqualToString:dic[@"CFBundleURLName"]]){ + for (NSDictionary* dic in types) { + if ([@"weixin" isEqualToString:dic[@"CFBundleURLName"]]) { return dic[@"CFBundleURLSchemes"][0]; } } return nil; } + @end diff --git a/ios/Classes/FluwxStringUtil.m b/ios/Classes/FluwxStringUtil.m index d1b73ecb..ba4fa709 100644 --- a/ios/Classes/FluwxStringUtil.m +++ b/ios/Classes/FluwxStringUtil.m @@ -8,24 +8,17 @@ @implementation FluwxStringUtil + (BOOL)isBlank:(NSString *)string { - if (string == nil) { - return YES; - } - - if ([string isKindOfClass:[NSNull class]]) { - return YES; - } return [[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0; - } + (NSString *)nilToEmpty:(NSString *)string { return string == nil ? @"" : string; } + @end diff --git a/ios/Classes/ThumbnailHelper.h b/ios/Classes/ThumbnailHelper.h index 23b20cb6..0a1fe918 100644 --- a/ios/Classes/ThumbnailHelper.h +++ b/ios/Classes/ThumbnailHelper.h @@ -6,11 +6,12 @@ @interface ThumbnailHelper : NSObject -+ (UIImage *)compressImage:(UIImage *)image toByte:(NSUInteger)maxLength isPNG:(BOOL)isPNG; ++ (UIImage *)compressImage:(UIImage *)image toByte:(NSUInteger)maxLength isPNG:(BOOL)isPNG; /// NSData 压缩后转NSData /// @param imageData 来源data /// @param maxLength 压缩目标值,压缩结果在maxLength的0.9~1之间 + (NSData *)compressImageData:(NSData *)imageData toByte:(NSUInteger)maxLength; + @end diff --git a/ios/Classes/ThumbnailHelper.m b/ios/Classes/ThumbnailHelper.m index 02e012ee..744afb04 100644 --- a/ios/Classes/ThumbnailHelper.m +++ b/ios/Classes/ThumbnailHelper.m @@ -11,9 +11,9 @@ + (NSData *)compressImageData:(NSData *)imageData toByte:(NSUInteger)maxLength { // Compress by quality CGFloat compression = 1; NSData *data = imageData; - NSLog(@"压缩前 %lu %lu ",(unsigned long)data.length,maxLength); + NSLog(@"压缩前 %lu %lu", (unsigned long)data.length,maxLength); if (data.length < maxLength) return data; - + UIImage *image = [UIImage imageWithData:imageData]; CGFloat max = 1; CGFloat min = 0; @@ -29,20 +29,20 @@ + (NSData *)compressImageData:(NSData *)imageData toByte:(NSUInteger)maxLength { } } - NSLog(@"压缩第一次 %lu %lu ",(unsigned long)data.length,maxLength); + NSLog(@"压缩第一次 %lu %lu", (unsigned long)data.length,maxLength); if (data.length < maxLength) return data; UIImage *resultImage; - + resultImage = [UIImage imageWithData:data]; - + // Compress by size NSUInteger lastDataLength = 0; while (data.length > maxLength && data.length != lastDataLength) { lastDataLength = data.length; CGFloat ratio = (CGFloat) maxLength / data.length; CGSize size = CGSizeMake((NSUInteger) (resultImage.size.width * sqrtf(ratio)), - (NSUInteger) (resultImage.size.height * sqrtf(ratio))); // Use NSUInteger to prevent white blank + (NSUInteger) (resultImage.size.height * sqrtf(ratio))); // Use NSUInteger to prevent white blank UIGraphicsBeginImageContext(size); [resultImage drawInRect:CGRectMake(0, 0, size.width, size.height)]; resultImage = UIGraphicsGetImageFromCurrentImageContext(); @@ -50,7 +50,7 @@ + (NSData *)compressImageData:(NSData *)imageData toByte:(NSUInteger)maxLength { data = UIImageJPEGRepresentation(resultImage, compression); } - NSLog(@"压缩第二次%lu %lu ",(unsigned long)data.length,maxLength); + NSLog(@"压缩第二次 %lu %lu", (unsigned long)data.length,maxLength); return data; } @@ -59,7 +59,7 @@ + (UIImage *)compressImage:(UIImage *)image toByte:(NSUInteger)maxLength isPNG:( CGFloat compression = 1; NSData *data = UIImageJPEGRepresentation(image, compression); if (data.length < maxLength) return image; - + CGFloat max = 1; CGFloat min = 0; for (int i = 0; i < 6; ++i) { @@ -73,7 +73,7 @@ + (UIImage *)compressImage:(UIImage *)image toByte:(NSUInteger)maxLength isPNG:( break; } } - + UIImage *resultImage; if (isPNG) { NSData *tmp = UIImagePNGRepresentation([UIImage imageWithData:data]); @@ -81,24 +81,24 @@ + (UIImage *)compressImage:(UIImage *)image toByte:(NSUInteger)maxLength isPNG:( } else { resultImage = [UIImage imageWithData:data]; } - - + + if (data.length < maxLength) return resultImage; - + // Compress by size NSUInteger lastDataLength = 0; while (data.length > maxLength && data.length != lastDataLength) { lastDataLength = data.length; CGFloat ratio = (CGFloat) maxLength / data.length; CGSize size = CGSizeMake((NSUInteger) (resultImage.size.width * sqrtf(ratio)), - (NSUInteger) (resultImage.size.height * sqrtf(ratio))); // Use NSUInteger to prevent white blank + (NSUInteger) (resultImage.size.height * sqrtf(ratio))); // Use NSUInteger to prevent white blank UIGraphicsBeginImageContext(size); [resultImage drawInRect:CGRectMake(0, 0, size.width, size.height)]; resultImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); data = UIImageJPEGRepresentation(resultImage, compression); } - + return resultImage; } @@ -107,27 +107,28 @@ - (UIImage *)scaleFromImage:(UIImage *)image width:(CGSize)newSize { CGSize imageSize = image.size; CGFloat width = imageSize.width; CGFloat height = imageSize.height; - + if (width <= newSize.width && height <= newSize.height) { return image; } - + if (width == 0 || height == 0) { return image; } - + CGFloat widthFactor = newSize.width / width; CGFloat heightFactor = newSize.height / height; CGFloat scaleFactor = (widthFactor < heightFactor ? widthFactor : heightFactor); - + CGFloat scaledWidth = width * scaleFactor; CGFloat scaledHeight = height * scaleFactor; CGSize targetSize = CGSizeMake(scaledWidth, scaledHeight); - + UIGraphicsBeginImageContext(targetSize); [image drawInRect:CGRectMake(0, 0, scaledWidth, scaledHeight)]; UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newImage; } + @end diff --git a/ios/Classes/public/FluwxDelegate.h b/ios/Classes/public/FluwxDelegate.h index c6b3bdb2..fa9d1df0 100644 --- a/ios/Classes/public/FluwxDelegate.h +++ b/ios/Classes/public/FluwxDelegate.h @@ -15,4 +15,5 @@ + (instancetype)defaultManager; - (void)registerWxAPI:(NSString *)appId universalLink:(NSString *)universalLink; + @end From 202453e7363a3f5dba485f6ed49001c48e92a40c Mon Sep 17 00:00:00 2001 From: Alex Li Date: Mon, 4 Nov 2024 17:41:36 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=8E=A8=20Format=20more?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ios/Classes/FluwxPlugin.m | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/ios/Classes/FluwxPlugin.m b/ios/Classes/FluwxPlugin.m index c0369973..ed0d9df8 100644 --- a/ios/Classes/FluwxPlugin.m +++ b/ios/Classes/FluwxPlugin.m @@ -43,7 +43,7 @@ @interface FluwxPlugin() typedef void(^FluwxWXReqRunnable)(void); -@implementation FluwxPlugin { +@implementation FluwxPlugin { FlutterMethodChannel *_channel; WechatAuthSDK *_qrauth; BOOL _isRunning; @@ -134,7 +134,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result [self openWeChatInvoice:call result:result]; } else if ([@"selfCheck" isEqualToString:call.method]) { #ifndef __OPTIMIZE__ - [WXApi checkUniversalLinkReady:^(WXULCheckStep step, WXCheckULStepResult* result) { + [WXApi checkUniversalLinkReady:^(WXULCheckStep step, WXCheckULStepResult *result) { NSString *log = [NSString stringWithFormat:@"%@, %u, %@, %@", @(step), result.success, result.errorInfo, result.suggestion]; [self logToFlutterWithDetail:log]; }]; @@ -187,7 +187,7 @@ - (void)openWeChatInvoice:(FlutterMethodCall *)call result:(FlutterResult)result } - (void)registerApp:(FlutterMethodCall *)call result:(FlutterResult)result { - NSNumber* doOnIOS =call.arguments[@"iOS"]; + NSNumber *doOnIOS = call.arguments[@"iOS"]; if (![doOnIOS boolValue]) { result(@NO); @@ -277,7 +277,7 @@ - (void)handlePayment:(FlutterMethodCall *)call result:(FlutterResult)result { NSString *sign = call.arguments[@"sign"]; [FluwxDelegate defaultManager].extData = call.arguments[@"extData"]; - NSString * appId = call.arguments[@"appId"]; + NSString *appId = call.arguments[@"appId"]; PayReq *req = [[PayReq alloc] init]; req.openID = (appId == (id) [NSNull null]) ? nil : appId; req.partnerId = partnerId; @@ -393,7 +393,7 @@ - (void)handleOpenBusinessView:(FlutterMethodCall *)call result:(FlutterResult)r - (void)handelGetExtMsgWithCall:(FlutterMethodCall *)call result:(FlutterResult)result { result([FluwxDelegate defaultManager].extMsg); - [FluwxDelegate defaultManager].extMsg=nil; + [FluwxDelegate defaultManager].extMsg = nil; } @@ -443,14 +443,14 @@ - (BOOL)application:(UIApplication *)app } #ifndef SCENE_DELEGATE -- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nonnull))restorationHandler{ +- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *_Nonnull))restorationHandler{ // TODO: (if need) cache userActivity and handle it once WXApi is registered return [WXApi handleOpenUniversalLink:userActivity delegate:self]; } #endif #ifdef SCENE_DELEGATE -- (void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivity API_AVAILABLE(ios(13.0)) { +- (void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivity API_AVAILABLE(ios(13.0)) { // TODO: (if need) cache userActivity and handle it once WXApi is registered [WXApi handleOpenUniversalLink:userActivity delegate:self]; } @@ -532,7 +532,7 @@ - (void)shareImage:(FlutterMethodCall *)call result:(FlutterResult)result { imageData = flutterImageData.data; } - NSString * imageDataHash = sourceImage[@"imgDataHash"]; + NSString *imageDataHash = sourceImage[@"imgDataHash"]; FlutterStandardTypedData *flutterThumbData = call.arguments[fluwxKeyThumbData]; NSData *thumbData = nil; @@ -1030,7 +1030,7 @@ - (void)onReq:(BaseReq *)req { [result setValue:showMessageFromWXReq.country forKey:@"country"]; // Cache extMsg for later use (by calling 'getExtMsg') - [FluwxDelegate defaultManager].extMsg= wmm.messageExt; + [FluwxDelegate defaultManager].extMsg = wmm.messageExt; if (_isRunning) { [_channel invokeMethod:@"onWXShowMessageFromWX" arguments:result]; @@ -1053,7 +1053,7 @@ - (void)onReq:(BaseReq *)req { [result setValue:launchFromWXReq.country forKey:@"country"]; // Cache extMsg for later use (by calling 'getExtMsg') - [FluwxDelegate defaultManager].extMsg= wmm.messageExt; + [FluwxDelegate defaultManager].extMsg = wmm.messageExt; if (_isRunning) { [_channel invokeMethod:@"onWXLaunchFromWX" arguments:result]; @@ -1553,11 +1553,11 @@ - (SendMessageToWXReq *)requestWithText:(NSString *)text } - (NSString*)fetchWeChatAppId { - NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary]; - NSArray* types = infoDic[@"CFBundleURLTypes"]; - for (NSDictionary* dic in types) { - if ([@"weixin" isEqualToString:dic[@"CFBundleURLName"]]) { - return dic[@"CFBundleURLSchemes"][0]; + NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; + NSArray *types = infoDict[@"CFBundleURLTypes"]; + for (NSDictionary *dict in types) { + if ([@"weixin" isEqualToString:dict[@"CFBundleURLName"]]) { + return dict[@"CFBundleURLSchemes"][0]; } } return nil;