React Native-无法识别我的本机功能

时间:2019-06-30 14:12:32

标签: javascript react-native

我正在努力架桥以实现承诺。但是,react-native无法识别我的本机功能。我做了文档中的所有内容以及社区中看到的所有内容,但是没有任何效果。

下面是我想返回到JavaScript的函数。

 @objc  
func login( resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {

NSLog("Using \(String(describing: profile.version))")
let customAttributes : [String : Array<String>] = [THMCustomAttributes:
  ["ola"]]
profile.doProfileRequest(options: customAttributes, andCallbackBlock:
  {(result: [AnyHashable : Any]?) -> Void in
    let results:NSDictionary! = result! as NSDictionary
    let status:THMStatusCode  =
      THMStatusCode(rawValue:(results.value(forKey: THMProfileStatus) as!
        NSNumber).intValue)!
    self.sessionID = results.value(forKey: THMSessionID) as! String
    if(status == .ok)
    {
      resolve(self.sessionID)
    }
    NSLog("Profile completed with: %@ and session ID: \(self.sessionID)",
      status == .ok                  ? "OK"                   :
        status == .networkTimeoutError ? "Timed out"            :
        status == .connectionError ? "Connection Error"     :
        status == .hostNotFoundError ? "Host Not Found Error" :
        status == .internalError  ? "Internal Error"       :
        status == .interruptedError  ? "Interrupted Error"    :
      "Other" )
    Fingerprint.usefulSessionID = self.sessionID
})   

} -这是用于函数导出的代码:

#import "React/RCTBridgeModule.h"
@interface RCT_EXTERN_MODULE(Fingerprint, NSObject)
RCT_EXTERN_METHOD(
                  login
                  resolve: (RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject
                  )
@end

-下面是标题的代码:

#import "React/RCTBridgeModule.h"
#import "React/RCTEventDispatcher.h"
#import "React/RCTEventEmitter.h"
#import <TrustDefender/TrustDefender.h>

-Javascript代码

NativeModules.Fingerprint.login()
          .then(token => {
            // do something useful...
          })
          .catch(error => {
            throw error
          })

-设备中显示的错误

Error that appears in the Javascript

0 个答案:

没有答案