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

fix:crashed when send reponse back on iOS

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