[invites][links] Fix some iOS specific issues
This commit is contained in:
parent
8e2d03cc5a
commit
72a1d1d439
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#if __has_include(<FirebaseInvites/FirebaseInvites.h>)
|
#if __has_include(<FirebaseInvites/FirebaseInvites.h>)
|
||||||
#import "RNFirebaseEvents.h"
|
#import "RNFirebaseEvents.h"
|
||||||
|
#import "RNFirebaseLinks.h"
|
||||||
#import "RNFirebaseUtil.h"
|
#import "RNFirebaseUtil.h"
|
||||||
#import <FirebaseInvites/FirebaseInvites.h>
|
#import <FirebaseInvites/FirebaseInvites.h>
|
||||||
|
|
||||||
@ -88,7 +89,7 @@ RCT_EXPORT_METHOD(getInitialInvitation:(RCTPromiseResolveBlock)resolve rejecter:
|
|||||||
url = userActivity.webpageURL;
|
url = userActivity.webpageURL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url) {
|
if (url) {
|
||||||
[FIRInvites handleUniversalLink:url completion:^(FIRReceivedInvite * _Nullable receivedInvite, NSError * _Nullable error) {
|
[FIRInvites handleUniversalLink:url completion:^(FIRReceivedInvite * _Nullable receivedInvite, NSError * _Nullable error) {
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -121,7 +122,7 @@ RCT_EXPORT_METHOD(sendInvitation:(NSDictionary *) invitation
|
|||||||
[inviteDialog setInviteDelegate: self];
|
[inviteDialog setInviteDelegate: self];
|
||||||
[inviteDialog setMessage:invitation[@"message"]];
|
[inviteDialog setMessage:invitation[@"message"]];
|
||||||
[inviteDialog setTitle:invitation[@"title"]];
|
[inviteDialog setTitle:invitation[@"title"]];
|
||||||
|
|
||||||
if (invitation[@"androidClientId"]) {
|
if (invitation[@"androidClientId"]) {
|
||||||
FIRInvitesTargetApplication *targetApplication = [[FIRInvitesTargetApplication alloc] init];
|
FIRInvitesTargetApplication *targetApplication = [[FIRInvitesTargetApplication alloc] init];
|
||||||
targetApplication.androidClientID = invitation[@"androidClientId"];
|
targetApplication.androidClientID = invitation[@"androidClientId"];
|
||||||
@ -139,11 +140,11 @@ RCT_EXPORT_METHOD(sendInvitation:(NSDictionary *) invitation
|
|||||||
if (invitation[@"deepLink"]) {
|
if (invitation[@"deepLink"]) {
|
||||||
[inviteDialog setDeepLink:invitation[@"deepLink"]];
|
[inviteDialog setDeepLink:invitation[@"deepLink"]];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the promise details for later
|
// Save the promise details for later
|
||||||
_invitationsRejecter = reject;
|
_invitationsRejecter = reject;
|
||||||
_invitationsResolver = resolve;
|
_invitationsResolver = resolve;
|
||||||
|
|
||||||
// Open the invitation dialog
|
// Open the invitation dialog
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[inviteDialog open];
|
[inviteDialog open];
|
||||||
@ -155,11 +156,13 @@ RCT_EXPORT_METHOD(sendInvitation:(NSDictionary *) invitation
|
|||||||
return [FIRInvites handleUniversalLink:url completion:^(FIRReceivedInvite * _Nullable receivedInvite, NSError * _Nullable error) {
|
return [FIRInvites handleUniversalLink:url completion:^(FIRReceivedInvite * _Nullable receivedInvite, NSError * _Nullable error) {
|
||||||
if (error) {
|
if (error) {
|
||||||
NSLog(@"Failed to handle invitation: %@", [error localizedDescription]);
|
NSLog(@"Failed to handle invitation: %@", [error localizedDescription]);
|
||||||
} else if (receivedInvite) {
|
} else if (receivedInvite && receivedInvite.inviteId) {
|
||||||
[RNFirebaseUtil sendJSEvent:self name:LINKS_LINK_RECEIVED body:@{
|
[RNFirebaseUtil sendJSEvent:self name:INVITES_INVITATION_RECEIVED body:@{
|
||||||
@"deepLink": receivedInvite.deepLink,
|
@"deepLink": receivedInvite.deepLink,
|
||||||
@"invitationId": receivedInvite.inviteId,
|
@"invitationId": receivedInvite.inviteId,
|
||||||
}];
|
}];
|
||||||
|
} else {
|
||||||
|
[[RNFirebaseLinks instance] sendLink:receivedInvite.deepLink];
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options;
|
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options;
|
||||||
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *))restorationHandler;
|
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *))restorationHandler;
|
||||||
|
- (void)sendLink:(NSString *)link;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@ -22,3 +23,4 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ RCT_EXPORT_MODULE();
|
|||||||
FIRDynamicLink *dynamicLink = [[FIRDynamicLinks dynamicLinks] dynamicLinkFromCustomSchemeURL:url];
|
FIRDynamicLink *dynamicLink = [[FIRDynamicLinks dynamicLinks] dynamicLinkFromCustomSchemeURL:url];
|
||||||
if (dynamicLink && dynamicLink.url) {
|
if (dynamicLink && dynamicLink.url) {
|
||||||
NSURL* url = dynamicLink.url;
|
NSURL* url = dynamicLink.url;
|
||||||
[RNFirebaseUtil sendJSEvent:self name:LINKS_LINK_RECEIVED body:url];
|
[RNFirebaseUtil sendJSEvent:self name:LINKS_LINK_RECEIVED body:url.absoluteString];
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
return NO;
|
return NO;
|
||||||
@ -56,7 +56,7 @@ continueUserActivity:(NSUserActivity *)userActivity
|
|||||||
NSLog(@"Failed to handle universal link: %@", [error localizedDescription]);
|
NSLog(@"Failed to handle universal link: %@", [error localizedDescription]);
|
||||||
} else {
|
} else {
|
||||||
NSURL* url = dynamicLink ? dynamicLink.url : userActivity.webpageURL;
|
NSURL* url = dynamicLink ? dynamicLink.url : userActivity.webpageURL;
|
||||||
[RNFirebaseUtil sendJSEvent:self name:LINKS_LINK_RECEIVED body:url];
|
[RNFirebaseUtil sendJSEvent:self name:LINKS_LINK_RECEIVED body:url.absoluteString];
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
@ -66,11 +66,15 @@ continueUserActivity:(NSUserActivity *)userActivity
|
|||||||
// ** Finish AppDelegate methods
|
// ** Finish AppDelegate methods
|
||||||
// *******************************************************
|
// *******************************************************
|
||||||
|
|
||||||
|
- (void)sendLink:(NSString *)link {
|
||||||
|
[RNFirebaseUtil sendJSEvent:self name:LINKS_LINK_RECEIVED body:link];
|
||||||
|
}
|
||||||
|
|
||||||
// ** Start React Module methods **
|
// ** Start React Module methods **
|
||||||
RCT_EXPORT_METHOD(createDynamicLink: (NSDictionary *) metadata resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
RCT_EXPORT_METHOD(createDynamicLink: (NSDictionary *) metadata resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
||||||
@try {
|
@try {
|
||||||
FIRDynamicLinkComponents *components = [self getDynamicLinkComponentsFromMetadata:metadata];
|
FIRDynamicLinkComponents *components = [self getDynamicLinkComponentsFromMetadata:metadata];
|
||||||
|
|
||||||
if (components == nil) {
|
if (components == nil) {
|
||||||
reject(@"links/failure", @"Failed to create Dynamic Link", nil);
|
reject(@"links/failure", @"Failed to create Dynamic Link", nil);
|
||||||
} else {
|
} else {
|
||||||
@ -140,11 +144,11 @@ RCT_EXPORT_METHOD(getInitialLink:(RCTPromiseResolveBlock)resolve rejecter:(RCTPr
|
|||||||
NSURL *link = [NSURL URLWithString:metadata[@"link"]];
|
NSURL *link = [NSURL URLWithString:metadata[@"link"]];
|
||||||
FIRDynamicLinkComponents *components =
|
FIRDynamicLinkComponents *components =
|
||||||
[FIRDynamicLinkComponents componentsWithLink:link domain:metadata[@"dynamicLinkDomain"]];
|
[FIRDynamicLinkComponents componentsWithLink:link domain:metadata[@"dynamicLinkDomain"]];
|
||||||
|
|
||||||
[self setAndroidParameters:metadata components:components];
|
[self setAndroidParameters:metadata components:components];
|
||||||
[self setIosParameters:metadata components:components];
|
[self setIosParameters:metadata components:components];
|
||||||
[self setSocialMetaTagParameters:metadata components:components];
|
[self setSocialMetaTagParameters:metadata components:components];
|
||||||
|
|
||||||
return components;
|
return components;
|
||||||
}
|
}
|
||||||
@catch(NSException * e) {
|
@catch(NSException * e) {
|
||||||
@ -159,7 +163,7 @@ RCT_EXPORT_METHOD(getInitialLink:(RCTPromiseResolveBlock)resolve rejecter:(RCTPr
|
|||||||
if (androidParametersDict) {
|
if (androidParametersDict) {
|
||||||
FIRDynamicLinkAndroidParameters *androidParams = [FIRDynamicLinkAndroidParameters
|
FIRDynamicLinkAndroidParameters *androidParams = [FIRDynamicLinkAndroidParameters
|
||||||
parametersWithPackageName: androidParametersDict[@"androidPackageName"]];
|
parametersWithPackageName: androidParametersDict[@"androidPackageName"]];
|
||||||
|
|
||||||
if (androidParametersDict[@"androidFallbackLink"]) {
|
if (androidParametersDict[@"androidFallbackLink"]) {
|
||||||
androidParams.fallbackURL = [NSURL URLWithString:androidParametersDict[@"androidFallbackLink"]];
|
androidParams.fallbackURL = [NSURL URLWithString:androidParametersDict[@"androidFallbackLink"]];
|
||||||
}
|
}
|
||||||
|
@ -10,11 +10,7 @@ import { getNativeModule } from '../../utils/native';
|
|||||||
|
|
||||||
import type App from '../core/app';
|
import type App from '../core/app';
|
||||||
|
|
||||||
const EVENT_TYPE = {
|
const NATIVE_EVENTS = ['links_link_received'];
|
||||||
Link: 'links_link_received',
|
|
||||||
};
|
|
||||||
|
|
||||||
const NATIVE_EVENTS = [EVENT_TYPE.Link];
|
|
||||||
|
|
||||||
export const MODULE_NAME = 'RNFirebaseLinks';
|
export const MODULE_NAME = 'RNFirebaseLinks';
|
||||||
export const NAMESPACE = 'links';
|
export const NAMESPACE = 'links';
|
||||||
@ -94,10 +90,6 @@ export default class Links extends ModuleBase {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get EVENT_TYPE(): Object {
|
|
||||||
return EVENT_TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create long Dynamic Link from parameters
|
* Create long Dynamic Link from parameters
|
||||||
* @param parameters
|
* @param parameters
|
||||||
@ -153,6 +145,4 @@ export default class Links extends ModuleBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const statics = {
|
export const statics = {};
|
||||||
EVENT_TYPE,
|
|
||||||
};
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user