最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Reactnative-iOS回調(diào)Javascript的方法

 更新時間:2018年09月03日 10:07:31   作者:FlyElephant  
這篇文章主要介紹了Reactnative-iOS回調(diào)Javascript的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

Reactnative可以調(diào)用原生模塊,原生模塊也可以給JavaScript發(fā)送事件通知.最好的方法是繼承RCTEventEmitter.自定義繼承自PushEventEmitter的子類RCTEventEmitter.

#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>

@interface PushEventEmitter : RCTEventEmitter <RCTBridgeModule>

- (void)addEventReminderReceived:(NSNotification *)notification;

@end

實現(xiàn)supportedEvents方法

#import "PushEventEmitter.h"

@implementation PushEventEmitter

+ (id)allocWithZone:(NSZone *)zone {
  static PushEventEmitter *sharedInstance = nil;
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
    sharedInstance = [super allocWithZone:zone];
  });
  return sharedInstance;
}

RCT_EXPORT_MODULE();

- (NSArray<NSString *> *)supportedEvents
{
  return @[@"EventReminder"];
}

- (void)addEventReminderReceived:(NSNotification *)notification {
  [self sendEventWithName:@"EventReminder" body:@{@"name": @"FlyElephant"}];
}

@end

React native 設置:

import {
  NativeModules,
  NativeEventEmitter,
} from 'react-native';

const PushEventEmitter = NativeModules.PushEventEmitter;

const emitterManager = new NativeEventEmitter(PushEventEmitter);

訂閱通知和移除通知:

  componentDidMount() {
    subscription = emitterManager.addListener(
      'EventReminder',
      (reminder) => console.log('JavaScript接收到通知:'+reminder.name)
    );

  }
  componentWillUnmount(){
    subscription.remove();// 移除通知
  }

調(diào)用測試:

PushEventEmitter *eventEmitter = [PushEventEmitter allocWithZone:nil];

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論

桐柏县| 班玛县| 鸡泽县| 大冶市| 英德市| 阳东县| 德清县| 娄烦县| 阜新| 平安县| 蒲城县| 陵水| 曲水县| 青神县| 横峰县| 桂平市| 威信县| 保山市| 获嘉县| 四平市| 华宁县| 盱眙县| 拉萨市| 恩施市| 崇文区| 鲁山县| 连南| 新蔡县| 丰原市| 枣庄市| 荃湾区| 樟树市| 健康| 古蔺县| 巨鹿县| 东兰县| 通道| 福清市| 柳州市| 西城区| 灌云县|