//
//  base.m
//  arena
//  设备相关
//  Created by 张琳 on 2017/10/28.
//  Copyright © 2017年 江苏斑马软件技术有限公司. All rights reserved.
//

#import "base.h"

@implementation base

/* 导出模块 */
RCT_EXPORT_MODULE(base);

/// 获取通用唯一标识码
/// - Parameter getUUID:获取UUID的参数
/// - Parameter findEvents: 获取UUID的结果回到
RCT_EXPORT_METHOD(getUUID:(NSDictionary *)param findEvents:(RCTResponseSenderBlock)callback)
{
    NSLog(@"原生接收到的RN参数:%@",param);
    
    NSMutableDictionary * finalParam = [[NSMutableDictionary alloc]init];
    [finalParam setValue:@"arena.device.base.getUUID" forKey:@"method"];
    [finalParam setValue:param forKey:@"params"];
    [finalParam setValue:@"rn" forKey:@"type"];
    
    
    void (^successBlock)(id) = ^(id result){
        callback(@[[NSNull null], result]);
    };
    
    void (^failedBlock)(id) = ^(id result){
        callback(@[result,[NSNull null]]);
    };
    
    NSDictionary *dic = @{@"success":successBlock , @"failed":failedBlock};
    
    /* 主要这里必须使用主线程发送,不然有可能失效 */
    dispatch_async(dispatch_get_main_queue(), ^{
        /* 把收到的RN的参数用通知发送出去 */
        [[NSNotificationCenter defaultCenter] postNotificationName:@"dispatch" object:dic userInfo:finalParam];
    });
}

@end
