Skip to content

Commit

Permalink
[ios] update RCTEventEmitter usage
Browse files Browse the repository at this point in the history
  • Loading branch information
rt2zz committed Jul 21, 2016
1 parent 6703e5c commit de69943
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ios/RNBranch.h
Expand Up @@ -6,9 +6,9 @@
//

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

@interface RNBranch : NSObject <RCTBridgeModule>
@interface RNBranch : RCTEventEmitter

+ (void)initSessionWithLaunchOptions:(NSDictionary *)launchOptions isReferrable:(BOOL)isReferrable;
+ (BOOL)handleDeepLink:(NSURL *)url;
Expand Down
16 changes: 10 additions & 6 deletions ios/RNBranch.m
Expand Up @@ -19,10 +19,14 @@ @implementation RNBranch
static NSDictionary* initSessionWithLaunchOptionsResult;
static NSURL* sourceUrl;

@synthesize bridge = _bridge;

RCT_EXPORT_MODULE();

- (NSArray *)supportedEvents
{
return @[@"RNBranch.initSessionSuccess",
@"RNBranch.initSessionError"];
}

//Called by AppDelegate.m -- stores initSession result in static variables and raises initSessionFinished event that's captured by the RNBranch instance to emit it to React Native
+ (void)initSessionWithLaunchOptions:(NSDictionary *)launchOptions isReferrable:(BOOL)isReferrable {
[[Branch getInstance] initSessionWithLaunchOptions:launchOptions isReferrable:isReferrable andRegisterDeepLinkHandler:^(NSDictionary *params, NSError *error) {
Expand Down Expand Up @@ -74,12 +78,12 @@ - (void) onInitSessionFinished:(NSNotification*) notification {

// If there is an error, fire error event
if (notificationObject[@"error"] != [NSNull null]) {
[self.bridge.eventDispatcher sendAppEventWithName:@"RNBranch.initSessionError" body:notificationObject];
[self sendEventWithName:@"RNBranch.initSessionError" body:notificationObject];
}

// otherwise notify the session is finished
else {
[self.bridge.eventDispatcher sendAppEventWithName:@"RNBranch.initSessionSuccess" body:notificationObject];
[self sendEventWithName:@"RNBranch.initSessionSuccess" body:notificationObject];
}
}

Expand Down Expand Up @@ -172,12 +176,12 @@ - (BranchLinkProperties*) createLinkProperties:(NSDictionary *)linkPropertiesMap
){
dispatch_async(dispatch_get_main_queue(), ^(void){
BranchUniversalObject *branchUniversalObject = [self createBranchUniversalObject:branchUniversalObjectMap];

NSMutableDictionary *mutableControlParams = [controlParamsMap mutableCopy];
if (shareOptionsMap && [shareOptionsMap objectForKey:@"emailSubject"]) {
[mutableControlParams setValue:[shareOptionsMap objectForKey:@"emailSubject"] forKey:@"$email_subject"];
}

BranchLinkProperties *linkProperties = [self createLinkProperties:linkPropertiesMap withControlParams:mutableControlParams];

UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
Expand Down

0 comments on commit de69943

Please sign in to comment.