我正在实现自己的模块,但在将参数快速传递给函数时遇到问题。该函数应该返回 Promise。它总是因这个错误而崩溃
Exception 'getPassesOf: is not a recognized Objective-C method.' was thrown while invoking getPassesOf on target RNAppleWallet with params ( DDDDtest, 5026, 5027 )
我的 OC 桥:
#import "React/RCTBridgeModule.h"
@interface RCT_EXTERN_MODULE(RNAppleWallet, NSObject)
RCT_EXTERN_METHOD(openWallet:(NSDictionary*)config callback:(RCTResponseSenderBlock))
...
RCT_EXTERN_METHOD(getPasses: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(getPassesOf: (NSString *)test (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
//RCT_EXTERN_METHOD(getPassesOf:(NSString*)passType (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
//RCT_EXTERN_METHOD(getPassesOf:(NSString *)passType resolve:(RCTPromiseResolveBlock *)resolve reject:(RCTPromiseRejectBlock *)reject)
...
@end
重要的功能 getRemoteSecureElementPasses
,getRemotePaymentPasses
并且getPasses
工作正常。但是他们没有额外的参数和功能getPassesOf
与 pramateter 测试崩溃
RCT_EXTERN_METHOD(getPassesOf: (NSString *)test (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
这是 swift 函数中的一个实现,getPsses
工作正常,但getPassesOf
该参数有问题
...
@objc
func getPasses(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
let passes = passLib.passes();
let passesArray = convertPassesToJsonString(passes:passes)
resolve(passesArray)
}
@objc
func getPassesOf(_ test: String, resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void{
print("===================================================")
print(test)
resolve("cus")
}
...
有趣的是当我删除参数时test
一切正常......但我需要它
这就是我在 RN 中调用它的方式,它getPasses
可以正常getPassesOf
工作:
...
public async getPasses(): Promise<PassType[]> {
const passData = await this.walletModule.getPasses();
return passData.map(pass => JSON.parse(pass));
}
public async getPassesOf(passType: string): Promise<PassType[]> {
// const passesOf = await this.walletModule.getPassesOf();
const passesOf = await this.walletModule.getPassesOf('DDDDtest');
return passesOf.map(pass => JSON.parse(pass));
}
...
更新:
我删除了返回类型-> Void
bud 没有任何改变仍然不起作用
前:
@objc func getPassesOf(_ test: String, resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void{
后:
@objc func getPassesOf(_ test: String, resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {