[ios] support dynamic links recieve
This commit is contained in:
parent
012f8b79b1
commit
748e3fb53d
|
@ -36,4 +36,7 @@ static NSString *const MESSAGING_NOTIFICATION_RECEIVED = @"messaging_notificatio
|
|||
static NSString *const ADMOB_INTERSTITIAL_EVENT = @"interstitial_event";
|
||||
static NSString *const ADMOB_REWARDED_VIDEO_EVENT = @"rewarded_video_event";
|
||||
|
||||
// Links
|
||||
static NSString *const LINKS_DYNAMIC_LINK_RECEIVED = @"dynamic_link_received";
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#if __has_include(<FirebaseAnalytics/FIRAnalytics.h>)
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <React/RCTEventEmitter.h>
|
||||
|
||||
@interface RNFirebaseAnalytics : NSObject <RCTBridgeModule> {
|
||||
|
||||
|
|
|
@ -5,11 +5,12 @@
|
|||
|
||||
#if __has_include(<FirebaseDynamicLinks/FIRDynamicLinks.h>)
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <React/RCTEventEmitter.h>
|
||||
|
||||
@interface RNFirebaseLinks : NSObject<RCTBridgeModule> {
|
||||
@interface RNFirebaseLinks : RCTEventEmitter<RCTBridgeModule> {
|
||||
|
||||
}
|
||||
|
||||
+ (void)sendDynamicLink:(nonnull NSURL *)link;
|
||||
@end
|
||||
|
||||
#else
|
||||
|
|
|
@ -2,13 +2,50 @@
|
|||
#import "Firebase.h"
|
||||
|
||||
#if __has_include(<FirebaseDynamicLinks/FIRDynamicLink.h>)
|
||||
#import "RNFirebaseEvents.h"
|
||||
@implementation RNFirebaseLinks
|
||||
|
||||
RCT_EXPORT_MODULE();
|
||||
|
||||
RCT_EXPORT_METHOD(createDynamicLink: (NSDictionary *) metadata resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
||||
FIRDynamicLinkComponents *components = [self setDynamicLinkBuilderFromMap:metadata];
|
||||
+ (void)sendDynamicLink:(nonnull NSURL *)link {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:LINKS_DYNAMIC_LINK_RECEIVED object:self userInfo:@{@"link": link}];
|
||||
}
|
||||
|
||||
|
||||
- (id)init {
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
NSLog(@"Setting up RNFirebaseLinks instance");
|
||||
[self initialiseLinks];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)initialiseLinks {
|
||||
// Establish Firebase managed data channel
|
||||
//[FIRMessaging messaging].shouldEstablishDirectChannel = YES;
|
||||
|
||||
|
||||
// Set up internal listener to send notification over bridge
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(sendEvent:)
|
||||
name:LINKS_DYNAMIC_LINK_RECEIVED
|
||||
object:nil];
|
||||
|
||||
// Set this as a delegate for FIRMessaging
|
||||
// dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// [FIRMessaging messaging].delegate = self;
|
||||
// });
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
|
||||
RCT_EXPORT_METHOD(createDynamicLink: (NSDictionary *) metadata resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
||||
FIRDynamicLinkComponents *components = [self getDynamicLinkComponentsFromMetadata:metadata];
|
||||
|
||||
if (components == nil) {
|
||||
reject(@"links/failure", @"error", nil);
|
||||
} else {
|
||||
|
@ -19,8 +56,8 @@ RCT_EXPORT_METHOD(createDynamicLink: (NSDictionary *) metadata resolver:(RCTProm
|
|||
}
|
||||
|
||||
RCT_EXPORT_METHOD(createShortDynamicLink: (NSDictionary *) metadata resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
||||
FIRDynamicLinkComponents *components = [self setDynamicLinkBuilderFromMap:metadata];
|
||||
|
||||
FIRDynamicLinkComponents *components = [self getDynamicLinkComponentsFromMetadata:metadata];
|
||||
|
||||
[components shortenWithCompletion:^(NSURL *_Nullable shortURL,
|
||||
NSArray *_Nullable warnings,
|
||||
NSError *_Nullable error) {
|
||||
|
@ -34,8 +71,12 @@ RCT_EXPORT_METHOD(createShortDynamicLink: (NSDictionary *) metadata resolver:(RC
|
|||
}];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(getInitialLink: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
||||
resolve(nil);
|
||||
}
|
||||
|
||||
- (FIRDynamicLinkComponents *)setDynamicLinkBuilderFromMap:(NSDictionary *)metadata {
|
||||
|
||||
- (FIRDynamicLinkComponents *)getDynamicLinkComponentsFromMetadata:(NSDictionary *)metadata {
|
||||
NSURL *link = [NSURL URLWithString:metadata[@"link"]];
|
||||
FIRDynamicLinkComponents *components =
|
||||
[FIRDynamicLinkComponents componentsWithLink:link domain:metadata[@"dynamicLinkDomain"]];
|
||||
|
@ -175,6 +216,15 @@ RCT_EXPORT_METHOD(createShortDynamicLink: (NSDictionary *) metadata resolver:(RC
|
|||
}
|
||||
}
|
||||
|
||||
- (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
|
||||
|
||||
#else
|
||||
|
|
Loading…
Reference in New Issue