[ios] support dynamic links recieve cont.
This commit is contained in:
parent
748e3fb53d
commit
705c03a4f1
|
@ -10,7 +10,19 @@
|
||||||
@interface RNFirebaseLinks : RCTEventEmitter<RCTBridgeModule> {
|
@interface RNFirebaseLinks : RCTEventEmitter<RCTBridgeModule> {
|
||||||
|
|
||||||
}
|
}
|
||||||
+ (void)sendDynamicLink:(nonnull NSURL *)link;
|
+ (BOOL)application:(UIApplication *)app
|
||||||
|
openURL:(NSURL *)url
|
||||||
|
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options;
|
||||||
|
|
||||||
|
+ (BOOL)application:(UIApplication *)application
|
||||||
|
openURL:(NSURL *)url
|
||||||
|
sourceApplication:(NSString *)sourceApplication
|
||||||
|
annotation:(id)annotation;
|
||||||
|
|
||||||
|
+ (BOOL)application:(UIApplication *)application
|
||||||
|
continueUserActivity:(NSUserActivity *)userActivity
|
||||||
|
restorationHandler:(void (^)(NSArray *))restorationHandler;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -3,45 +3,90 @@
|
||||||
|
|
||||||
#if __has_include(<FirebaseDynamicLinks/FIRDynamicLink.h>)
|
#if __has_include(<FirebaseDynamicLinks/FIRDynamicLink.h>)
|
||||||
#import "RNFirebaseEvents.h"
|
#import "RNFirebaseEvents.h"
|
||||||
|
|
||||||
|
|
||||||
|
static void sendDynamicLink(NSURL *url, id sender) {
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:LINKS_DYNAMIC_LINK_RECEIVED
|
||||||
|
object:sender
|
||||||
|
userInfo:@{@"url": url.absoluteString}];
|
||||||
|
}
|
||||||
|
|
||||||
@implementation RNFirebaseLinks
|
@implementation RNFirebaseLinks
|
||||||
|
|
||||||
RCT_EXPORT_MODULE();
|
RCT_EXPORT_MODULE();
|
||||||
|
|
||||||
+ (void)sendDynamicLink:(nonnull NSURL *)link {
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:LINKS_DYNAMIC_LINK_RECEIVED object:self userInfo:@{@"link": link}];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (id)init {
|
- (id)init {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self != nil) {
|
if (self != nil) {
|
||||||
NSLog(@"Setting up RNFirebaseLinks instance");
|
NSLog(@"Setting up RNFirebaseLinks instance");
|
||||||
[self initialiseLinks];
|
[self initializeLinks];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)initialiseLinks {
|
- (void)initializeLinks {
|
||||||
// Establish Firebase managed data channel
|
|
||||||
//[FIRMessaging messaging].shouldEstablishDirectChannel = YES;
|
|
||||||
|
|
||||||
|
|
||||||
// Set up internal listener to send notification over bridge
|
// Set up internal listener to send notification over bridge
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
selector:@selector(sendEvent:)
|
selector:@selector(sendDynamicLinkEvent:)
|
||||||
name:LINKS_DYNAMIC_LINK_RECEIVED
|
name:LINKS_DYNAMIC_LINK_RECEIVED
|
||||||
object:nil];
|
object:nil];
|
||||||
|
|
||||||
// Set this as a delegate for FIRMessaging
|
|
||||||
// dispatch_async(dispatch_get_main_queue(), ^{
|
|
||||||
// [FIRMessaging messaging].delegate = self;
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (BOOL)application:(UIApplication *)app
|
||||||
|
openURL:(NSURL *)url
|
||||||
|
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
|
||||||
|
sendDynamicLink(url, self);
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (BOOL)application:(UIApplication *)application
|
||||||
|
openURL:(NSURL *)url
|
||||||
|
sourceApplication:(NSString *)sourceApplication
|
||||||
|
annotation:(id)annotation
|
||||||
|
{
|
||||||
|
sendDynamicLink(url, self);
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (BOOL)application:(UIApplication *)application
|
||||||
|
continueUserActivity:(NSUserActivity *)userActivity
|
||||||
|
restorationHandler:(void (^)(NSArray *))restorationHandler
|
||||||
|
{
|
||||||
|
if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
|
||||||
|
sendDynamicLink(userActivity.webpageURL, self);
|
||||||
|
}
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSArray<NSString *> *)supportedEvents {
|
||||||
|
return @[LINKS_DYNAMIC_LINK_RECEIVED];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)sendDynamicLinkEvent:(NSNotification *)notification {
|
||||||
|
[self sendEventWithName:LINKS_DYNAMIC_LINK_RECEIVED body:notification.userInfo[@"url"]];
|
||||||
|
}
|
||||||
|
|
||||||
|
RCT_EXPORT_METHOD(getInitialLink:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
||||||
|
NSURL *initialLink = nil;
|
||||||
|
if (self.bridge.launchOptions[UIApplicationLaunchOptionsURLKey]) {
|
||||||
|
initialLink = self.bridge.launchOptions[UIApplicationLaunchOptionsURLKey];
|
||||||
|
} else {
|
||||||
|
NSDictionary *userActivityDictionary =
|
||||||
|
self.bridge.launchOptions[UIApplicationLaunchOptionsUserActivityDictionaryKey];
|
||||||
|
if ([userActivityDictionary[UIApplicationLaunchOptionsUserActivityTypeKey] isEqual:NSUserActivityTypeBrowsingWeb]) {
|
||||||
|
initialLink = ((NSUserActivity*) userActivityDictionary[@"UIApplicationLaunchOptionsUserActivityKey"]).webpageURL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NSString* initialLinkString = initialLink ? initialLink.absoluteString : (id)kCFNull;
|
||||||
|
resolve(initialLinkString);
|
||||||
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(createDynamicLink: (NSDictionary *) metadata resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
RCT_EXPORT_METHOD(createDynamicLink: (NSDictionary *) metadata resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
||||||
FIRDynamicLinkComponents *components = [self getDynamicLinkComponentsFromMetadata:metadata];
|
FIRDynamicLinkComponents *components = [self getDynamicLinkComponentsFromMetadata:metadata];
|
||||||
|
@ -71,10 +116,6 @@ RCT_EXPORT_METHOD(createShortDynamicLink: (NSDictionary *) metadata resolver:(RC
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(getInitialLink: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
|
||||||
resolve(nil);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (FIRDynamicLinkComponents *)getDynamicLinkComponentsFromMetadata:(NSDictionary *)metadata {
|
- (FIRDynamicLinkComponents *)getDynamicLinkComponentsFromMetadata:(NSDictionary *)metadata {
|
||||||
NSURL *link = [NSURL URLWithString:metadata[@"link"]];
|
NSURL *link = [NSURL URLWithString:metadata[@"link"]];
|
||||||
|
@ -216,14 +257,6 @@ RCT_EXPORT_METHOD(getInitialLink: (RCTPromiseResolveBlock)resolve rejecter:(RCTP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray<NSString *> *)supportedEvents {
|
|
||||||
return @[LINKS_DYNAMIC_LINK_RECEIVED];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)sendEvent:(NSNotification *)notification {
|
|
||||||
NSURL* dynamicLink = notification.userInfo[@"link"];
|
|
||||||
[self sendEventWithName:LINKS_DYNAMIC_LINK_RECEIVED body:dynamicLink.absoluteString];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue