使用 react-native-firebase 创建 Firebase 动态链接失败 - React Native
Posted
技术标签:
【中文标题】使用 react-native-firebase 创建 Firebase 动态链接失败 - React Native【英文标题】:Failed to create Firebase Dynamic Link using react-native-firebase - React Native 【发布时间】:2019-07-15 10:50:24 【问题描述】:最近我已将我的 React Native 应用程序更新到版本 0.59.10 ...我正在使用包 react-native-firebase 版本 5.5.5 将 Firebase 集成到我的应用程序中...我确实更新了这个包以及我的RN 应用程序。我正在使用上述包以编程方式创建动态链接...在升级之前,动态链接已成功创建,但在更新后,当我尝试创建动态链接时出现此错误。
Error: Failed to create Dynamic Link
at createErrorFromErrorData (NativeModules.js:155)
at NativeModules.js:104
at MessageQueue.__invokeCallback (MessageQueue.js:414)
at MessageQueue.js:127
at MessageQueue.__guard (MessageQueue.js:314)
at MessageQueue.invokeCallbackAndReturnFlushedQueue (MessageQueue.js:126)
at e (RNDebuggerWorker.js:1)
这是使用 react-native-firebase 文档中提到的以下方法创建的长链接。
const link =
new firebase.links.DynamicLink('https://example.com?param1=foo¶m2=bar', 'abc123.page.link')
.android.setPackageName('com.example.android')
.ios.setBundleId('com.example.ios');
firebase.links()
.createDynamicLink(link)
.then((url) =>
// ...
);
请注意,这仅在 iOS 中发生……在 Android 中,我可以成功生成长链接。
这是我在 RN Application 中的 JS 实现。
class Referral extends Component
state =
shareLink: ''
;
onShare = async () =>
try
const result = await Share.share(
message: 'Hey found this new great app for ordering ... You should try it as well.',
url: this.state.shareLink
);
if (result.action === Share.sharedAction)
if (result.activityType)
// shared with activity type of result.activityType
else
// shared
else if (result.action === Share.dismissedAction)
// dismissed
catch (error)
Alert.alert('Opps', error.message);
;
onPressTermsCondition = () =>
this.props.navigation.navigate('TermsAndConditions');
;
generateShareLink = async () =>
console.log('PRESSED');
const identifier = 'com.example.myapp';
const firebaseDynamicLinkPrefix = 'myapp.page.link';
const deepLink = 'https://www.example.com/?referralCode=foo&referralType=bar';
const shareLink = new firebase.links.DynamicLink(
deepLink,
firebaseDynamicLinkPrefix
).android
.setPackageName(identifier)
.ios.setBundleId(identifier);
console.log('SHARE LINK', shareLink);
firebase
.links()
.createDynamicLink(shareLink)
.then(url =>
// ...
console.log('LINK', url);
)
.catch(e => console.log('ERROR', e));
// firebase
// .links()
// .createShortDynamicLink(shareLink, 'UNGUESSABLE')
// .then(url =>
// // ...
// console.log('URL', url);
// this.setState( shareLink: url , () =>
// //this.onShare();
// console.log('LINK SAVED');
// );
// )
// .catch(e => console.log('ERROR', e));
;
render()
return (
<View style=styles.container>
<View style=styles.header>
<View style=styles.heading>
<Text style=styles.headingText>Refer a friend</Text>
</View>
<View style=styles.subHeading>
<Text style=styles.subHeadingText>Share the Eat'n Love</Text>
</View>
</View>
<View style=styles.content>
<View style=styles.imageContainer>
<Image source=friendsGroup style=styles.image />
</View>
<View style=styles.descriptionContainer>
<Text style=styles.descriptionText>
Get upto 10% discount when someone signs up using your referral code and
place their first order over $10. Your friend also gets $7 off.
</Text>
</View>
<View style=styles.sharingContainer>
<View style=styles.sharingDescriptionContainer>
<Text style=styles.sharingDescriptionText>Tap to share</Text>
</View>
<View style=styles.shareButtonContainer>
<TouchableOpacity
style=styles.shareButton
onPress=() => this.generateShareLink()
>
<View style=styles.shareIconContainer>
<Image source=shareIcon style=styles.shareIcon />
</View>
<View style=styles.referralCodeContainer>
<Text style=styles.referralCodeText>89sd8293</Text>
</View>
<View style=styles.emptyView />
</TouchableOpacity>
</View>
</View>
</View>
<View style=styles.termsContainer>
<Text style=styles.termsText onPress=() => this.onPressTermsCondition()>
Terms & Conditions
</Text>
</View>
</View>
);
export default Referral;
这是我的 POD 文件。
platform :ios, '9.0'
target 'MyApp' do
#pod 'Stripe', '~> 11.2.0'
#pod 'BVLinearGradient', :path => '../node_modules/react-native-linear-gradient'
#pod 'RNSound', :path => '../node_modules/react-native-sound'
# Required by RNFirebase
pod 'Firebase/Core', '~> 6.3.0'
pod 'Firebase/Messaging', '~> 6.3.0'
pod 'Firebase/RemoteConfig', '~> 6.3.0'
pod 'Firebase/Database', '~> 6.3.0'
pod 'Firebase/DynamicLinks', '~> 6.3.0'
#pod 'react-native-fbsdk', :path => '../node_modules/react-native-fbsdk'
#pod 'RNGoogleSignin', :path => '../node_modules/react-native-google-signin'
#pod 'RNDeviceInfo', :path => '../node_modules/react-native-device-info'
#pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-community/async-storage'
#pod 'RNGestureHandler', :path => '../node_modules/react-native-gesture-handler'
target 'MyAppTests' do
inherit! :search_paths
# Pods for testing
end
end
这是我的 AppDelegate.m。
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <Firebase.h>
#import "RNFirebaseMessaging.h"
#import "RNFirebaseNotifications.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <RNGoogleSignin/RNGoogleSignin.h>
#import "RNFirebaseLinks.h"
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "RNSplashScreen.h" // react native splash screen link
@implementation AppDelegate
- (void)applicationDidBecomeActive:(UIApplication *)application
[FBSDKAppEvents activateApp];
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
[FIROptions defaultOptions].deepLinkURLScheme = @"com.example.myapp";
[FIRApp configure];
[RNFirebaseNotifications configure];
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"MyApp"
initialProperties:nil];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
[RNSplashScreen show]; // react native splash screen link
return YES;
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
[[RNFirebaseNotifications instance] didReceiveLocalNotification:notification];
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo
fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler
[[RNFirebaseNotifications instance] didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
[[RNFirebaseMessaging instance] didRegisterUserNotificationSettings:notificationSettings];
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
return [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey] annotation:options[UIApplicationOpenURLOptionsAnnotationKey]]
|| [RNGoogleSignin application:application openURL:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey] annotation:options[UIApplicationOpenURLOptionsAnnotationKey]] || [[RNFirebaseLinks instance] application:application openURL:url options:options];
- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray *))restorationHandler
return [[RNFirebaseLinks instance] application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
@end
我一直试图在互联网上找到解决方案,但没有找到任何解决方案,所以我在这里求助于大师......请指出我正确的方向。 TIA
【问题讨论】:
【参考方案1】:改变
const firebaseDynamicLinkPrefix = 'myapp.page.link';
到
const firebaseDynamicLinkPrefix = 'https://myapp.page.link';
【讨论】:
以上是关于使用 react-native-firebase 创建 Firebase 动态链接失败 - React Native的主要内容,如果未能解决你的问题,请参考以下文章
使用 react-native-firebase 创建 Firebase 动态链接失败 - React Native
使用 react-native-firebase 在 React Native 上自定义通知
如何使用 react-native-firebase 在 iOS 设备的推送通知中添加按钮?
在设备上使用 react-native-firebase 检测文本要求计费