提交 2c645693 authored 作者: JarvanMo's avatar JarvanMo

fix:crashed when send reponse back on iOS

上级 76e3eacf
...@@ -17,6 +17,17 @@ ...@@ -17,6 +17,17 @@
} }
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [WXApi handleOpenURL:url delegate:[FluwxResponseHandler responseHandler]];
}
// NOTE: 9.0以后使用新API接口
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options
{
return [WXApi handleOpenURL:url delegate:[FluwxResponseHandler responseHandler]];
}
- (void)applicationWillResignActive:(UIApplication *)application { - (void)applicationWillResignActive:(UIApplication *)application {
} }
......
...@@ -54,7 +54,9 @@ class _PayPageState extends State<PayPage> { ...@@ -54,7 +54,9 @@ class _PayPageState extends State<PayPage> {
timeStamp: result['timestamp'].toString(), timeStamp: result['timestamp'].toString(),
sign: result['sign'].toString(), sign: result['sign'].toString(),
), ),
); ).then((data){
print("---》$data");
});
}, },
child: const Text("pay"), child: const Text("pay"),
), ),
......
...@@ -15,6 +15,9 @@ class _ShareTextPageState extends State<ShareTextPage> { ...@@ -15,6 +15,9 @@ class _ShareTextPageState extends State<ShareTextPage> {
void initState() { void initState() {
super.initState(); super.initState();
fluwx = new Fluwx(); fluwx = new Fluwx();
fluwx.response.listen((data){
print(data.toString());
});
} }
@override @override
...@@ -84,7 +87,9 @@ class _ShareTextPageState extends State<ShareTextPage> { ...@@ -84,7 +87,9 @@ class _ShareTextPageState extends State<ShareTextPage> {
fluwx.share(WeChatShareTextModel( fluwx.share(WeChatShareTextModel(
text: _text, text: _text,
transaction: "text${DateTime.now().millisecondsSinceEpoch}", transaction: "text${DateTime.now().millisecondsSinceEpoch}",
scene: scene)); scene: scene)).then((data){
print(data);
});
// fluwx.sendAuth(WeChatSendAuthModel(scope: "snsapi_userinfo",state: "wechat_sdk_demo_test")); // fluwx.sendAuth(WeChatSendAuthModel(scope: "snsapi_userinfo",state: "wechat_sdk_demo_test"));
} }
......
...@@ -12,6 +12,10 @@ ...@@ -12,6 +12,10 @@
BOOL isWeChatRegistered = NO; BOOL isWeChatRegistered = NO;
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
+ (void)registerWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar { + (void)registerWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar {
FlutterMethodChannel *channel = [FlutterMethodChannel FlutterMethodChannel *channel = [FlutterMethodChannel
...@@ -31,12 +35,16 @@ BOOL isWeChatRegistered = NO; ...@@ -31,12 +35,16 @@ BOOL isWeChatRegistered = NO;
_fluwxShareHandler = [[FluwxShareHandler alloc] initWithRegistrar:registrar]; _fluwxShareHandler = [[FluwxShareHandler alloc] initWithRegistrar:registrar];
_fluwxAuthHandler = [[FluwxAuthHandler alloc] initWithRegistrar:registrar]; _fluwxAuthHandler = [[FluwxAuthHandler alloc] initWithRegistrar:registrar];
_fluwxWXApiHandler = [[FluwxWXApiHandler alloc] init]; _fluwxWXApiHandler = [[FluwxWXApiHandler alloc] init];
_fluwxPaymentHandler = [[FluwxPaymentHandler alloc] init]; _fluwxPaymentHandler = [[FluwxPaymentHandler alloc] initWithRegistrar:registrar];
} }
return self; return self;
} }
- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
@implementation FluwxPaymentHandler @implementation FluwxPaymentHandler
- (instancetype)initWithRegistrar { - (instancetype)initWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
self = [super init]; self = [super init];
return self; return self;
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
NSString *nonceStr = call.arguments[@"nonceStr"]; NSString *nonceStr = call.arguments[@"nonceStr"];
UInt32 timeStamp = (UInt32) call.arguments[@"timeStamp"]; UInt32 timeStamp = (UInt32) call.arguments[@"timeStamp"];
NSString *sign = call.arguments[@"sign"]; NSString *sign = call.arguments[@"sign"];
BOOL done = [WXApiRequestHandler sendPayment:@"" BOOL done = [WXApiRequestHandler sendPayment:call.arguments[@"appId"]
PartnerId:partnerId PartnerId:partnerId
PrepayId:prepayId PrepayId:prepayId
NonceStr:nonceStr NonceStr:nonceStr
......
...@@ -7,4 +7,5 @@ ...@@ -7,4 +7,5 @@
@interface StringUtil : NSObject @interface StringUtil : NSObject
+ (BOOL) isBlank:(NSString *)string; + (BOOL) isBlank:(NSString *)string;
+ (NSString *) nilToEmpty:(NSString *) string;
@end @end
\ No newline at end of file
...@@ -25,4 +25,7 @@ ...@@ -25,4 +25,7 @@
} }
- (NSString *)nilToEmpty:(NSString *)string {
return string == nil?@"":string;
}
@end @end
\ No newline at end of file
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#import <Flutter/Flutter.h> #import <Flutter/Flutter.h>
#import "FluwxKeys.h" #import "FluwxKeys.h"
#import "WXApi.h" #import "WXApi.h"
#import "StringUtil.h"
@protocol WXApiManagerDelegate <NSObject> @protocol WXApiManagerDelegate <NSObject>
......
...@@ -36,7 +36,6 @@ FlutterMethodChannel *methodChannel = nil; ...@@ -36,7 +36,6 @@ FlutterMethodChannel *methodChannel = nil;
} }
#pragma mark - WXApiDelegate #pragma mark - WXApiDelegate
- (void)onResp:(BaseResp *)resp { - (void)onResp:(BaseResp *)resp {
if ([resp isKindOfClass:[SendMessageToWXResp class]]) { if ([resp isKindOfClass:[SendMessageToWXResp class]]) {
if (_delegate if (_delegate
...@@ -46,14 +45,19 @@ FlutterMethodChannel *methodChannel = nil; ...@@ -46,14 +45,19 @@ FlutterMethodChannel *methodChannel = nil;
// @{fluwxKeyPlatform: fluwxKeyIOS, fluwxKeyResult: @(done)} // @{fluwxKeyPlatform: fluwxKeyIOS, fluwxKeyResult: @(done)}
} }
SendMessageToWXResp *messageResp = (SendMessageToWXResp *) resp; SendMessageToWXResp *messageResp = (SendMessageToWXResp *) resp;
NSDictionary *result = @{ NSDictionary *result = @{
description: messageResp.description, description: messageResp.description == nil ?@"":messageResp.description,
errStr: messageResp.errStr, errStr: messageResp.errStr == nil ? @"":messageResp.errStr,
errCode: @(messageResp.errCode), errCode: @(messageResp.errCode),
type: @(messageResp.type), type: messageResp.type == nil ? @2 :@(messageResp.type),
country: messageResp.country, country: messageResp.country== nil ? @"":messageResp.country,
lang: messageResp.lang, lang: messageResp.lang == nil ? @"":messageResp.lang,
fluwxKeyPlatform: fluwxKeyIOS fluwxKeyPlatform: fluwxKeyIOS
}; };
[methodChannel invokeMethod:@"onShareResponse" arguments:result]; [methodChannel invokeMethod:@"onShareResponse" arguments:result];
...@@ -70,15 +74,15 @@ FlutterMethodChannel *methodChannel = nil; ...@@ -70,15 +74,15 @@ FlutterMethodChannel *methodChannel = nil;
SendAuthResp *authResp = (SendAuthResp *) resp; SendAuthResp *authResp = (SendAuthResp *) resp;
NSDictionary *result = @{ NSDictionary *result = @{
description: authResp.description, description: authResp.description == nil ?@"":authResp.description,
errStr: authResp.errStr, errStr: authResp.errStr == nil ?@"":authResp.errStr,
errCode: @(authResp.errCode), errCode: @(authResp.errCode),
type: @(authResp.type), type: authResp.type == nil ?@1:@(authResp.type),
country: authResp.country, country: authResp.country == nil? @"":authResp.country,
lang: authResp.lang, lang: authResp.lang == nil?@"":authResp.lang,
fluwxKeyPlatform: fluwxKeyIOS, fluwxKeyPlatform: fluwxKeyIOS,
@"code":authResp.code, @"code":[StringUtil nilToEmpty:authResp.code],
@"state":authResp.state @"state": [StringUtil nilToEmpty:authResp.state]
}; };
[methodChannel invokeMethod:@"onAuthResponse" arguments:result]; [methodChannel invokeMethod:@"onAuthResponse" arguments:result];
...@@ -131,10 +135,10 @@ FlutterMethodChannel *methodChannel = nil; ...@@ -131,10 +135,10 @@ FlutterMethodChannel *methodChannel = nil;
PayResp *payResp = (PayResp *) resp; PayResp *payResp = (PayResp *) resp;
NSDictionary *result = @{ NSDictionary *result = @{
description: payResp.description, description:[StringUtil nilToEmpty:payResp.description] ,
errStr: payResp.errStr, errStr: [StringUtil nilToEmpty:resp.errStr],
errCode: @(payResp.errCode), errCode: @(payResp.errCode),
type: @(payResp.type), type: payResp.type == nil ?@5:@(payResp.type),
fluwxKeyPlatform: fluwxKeyIOS, fluwxKeyPlatform: fluwxKeyIOS,
}; };
[methodChannel invokeMethod:@"onAuthResponse" arguments:result]; [methodChannel invokeMethod:@"onAuthResponse" arguments:result];
......
...@@ -382,6 +382,7 @@ ...@@ -382,6 +382,7 @@
+ (BOOL)sendPayment:(NSString *)appId PartnerId:(NSString *)partnerId PrepayId:(NSString *)prepayId NonceStr:(NSString *)nonceStr Timestamp:(UInt32)timestamp Package:(NSString *)package Sign:(NSString *)sign { + (BOOL)sendPayment:(NSString *)appId PartnerId:(NSString *)partnerId PrepayId:(NSString *)prepayId NonceStr:(NSString *)nonceStr Timestamp:(UInt32)timestamp Package:(NSString *)package Sign:(NSString *)sign {
PayReq *req = [[PayReq alloc] init]; PayReq *req = [[PayReq alloc] init];
req.openID = (appId == (id) [NSNull null]) ? nil : appId;
req.partnerId = partnerId; req.partnerId = partnerId;
req.prepayId = prepayId; req.prepayId = prepayId;
req.nonceStr = nonceStr; req.nonceStr = nonceStr;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论