Skip to content

Commit

Permalink
create static func for linking notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonnoahchoi committed May 2, 2017
1 parent d9caa9e commit d514b23
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions Libraries/LinkingIOS/RCTLinkingManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@
#import <React/RCTUtils.h>

NSString *const RCTOpenURLNotification = @"RCTOpenURLNotification";
id class;


static void postNotificationWithURL(NSURL *URL, id sender)
{
NSDictionary<NSString *, id> *payload = @{@"url": URL.absoluteString};
[[NSNotificationCenter defaultCenter] postNotificationName:RCTOpenURLNotification
object:sender
userInfo:payload];
}

@implementation RCTLinkingManager

RCT_EXPORT_MODULE()

- (dispatch_queue_t)methodQueue
{
class = self;
return dispatch_get_main_queue();
}

Expand All @@ -48,7 +55,7 @@ + (BOOL)application:(UIApplication *)app
openURL:(NSURL *)URL
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
postNotificationWithURL(URL);
postNotificationWithURL(URL, self);
return YES;
}

Expand All @@ -57,18 +64,10 @@ + (BOOL)application:(UIApplication *)application
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
postNotificationWithURL(URL);
postNotificationWithURL(URL, self);
return YES;
}

void postNotificationWithURL(NSURL *URL)
{
NSDictionary<NSString *, id> *payload = @{@"url": URL.absoluteString};
[[NSNotificationCenter defaultCenter] postNotificationName:RCTOpenURLNotification
object:class
userInfo:payload];
}

+ (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray *))restorationHandler
Expand Down

0 comments on commit d514b23

Please sign in to comment.