Created
August 27, 2016 16:21
-
-
Save andybangs/5f1ee78247b0346e24d55119c6a02afa to your computer and use it in GitHub Desktop.
Example using GSEventEmitter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import "RCTBridge.h" | |
@interface GSBeaconManager : NSObject <RCTBridgeModule> | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "GSBeaconManager.h" | |
#import "GSEventEmitter.h" | |
#import <Gimbal/Gimbal.h> | |
@interface GSBeaconManager () <GMBLBeaconManagerDelegate> | |
@property (nonatomic, strong) GMBLBeaconManager *beaconManager; | |
@end | |
@implementation GSBeaconManager | |
RCT_EXPORT_MODULE(); | |
RCT_EXPORT_METHOD(startListening){ | |
[[self beaconManager] startListening]; | |
} | |
- (instancetype)init { | |
self = [super init]; | |
if (self) { | |
[Gimbal setAPIKey:kGMBLKey options:nil]; | |
_beaconManager = [GMBLBeaconManager new]; | |
_beaconManager.delegate = self; | |
} | |
return self; | |
} | |
- (void)beaconManager:(GMBLBeaconManager *)manager didReceiveBeaconSighting:(GMBLBeaconSighting *)sighting { | |
NSString *beaconID = sighting.beacon.identifier; | |
[GSEventEmitter application:[UIApplication sharedApplication] beaconSighted:beaconID]; | |
} | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component, PropTypes } from 'react'; | |
import { NativeModules, NativeEventEmitter } from 'react-native'; | |
class Welcome extends Component { | |
constructor(props) { | |
super(props); | |
this.eventEmitter; | |
} | |
componentWillMount() { | |
const { GSBeaconManager, GSEventEmitter } = NativeModules; | |
const { addBeacon } = this.props.actions; | |
this.eventEmitter = new NativeEventEmitter(GSEventEmitter); | |
this.eventEmitter.addListener(GSEventEmitter.SIGHTED_BEACON, (data) => addBeacon(data.payload)); | |
GSBeaconManager.startListening(); | |
} | |
componentWillUnmount() { | |
this.eventEmitter.remove(); | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! This was really helpful for me 🥇