最近我已将我的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应用程序中的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
答案 0 :(得分:1)
更改
const firebaseDynamicLinkPrefix = 'myapp.page.link';
到
const firebaseDynamicLinkPrefix = 'https://myapp.page.link';