//
//  ScanCodeModule.m
//  cashpad
//
//  Created by 夏迎霖 on 2017/5/11.
//  Copyright © 2017年 Facebook. All rights reserved.
//

#import "ScanCodeModule.h"

@implementation ScanCode


RCT_EXPORT_MODULE();


- (NSArray<NSString *> *)supportedEvents
{
  return @[@"code"];  // 这里注意要和  [self sendEventWithName:@"QRCodeFromPhoto" body:@{ @"scanResult":scandResult, @"stateCode":@(self.stateCode), }]; 里面发送的事件名字一致，不然JS 端不会识别
}




// 接收传过来的 NSString
RCT_EXPORT_METHOD(create){
  NSLog(@"初始化键盘扫描");
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(event:)name:@"code" object:nil];
}

- (void)event:(NSNotification *)notification
{
  
  if(nil == notification.object){
    return;
  }
  
  dispatch_async(dispatch_get_main_queue(), ^{
    [self sendEventWithName:@"code" body: notification.object];
    // [self sendEventWithName:@"Bluetooth.discovery.over" body:notification.object];
    
  });
}

RCT_EXPORT_METHOD(destroy){
  [[NSNotificationCenter defaultCenter] removeObserver:self];
}

@end
