我目前正在通过RCTLinking API处理ios通用链接。出于某些原因,我需要使用Firebase动态链接,我想知道是否可以在我的应用程序中使用它们。 我的问题是实施:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
和
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
似乎不兼容,因为我需要返回RCTLinkingManager和RNFirebaseLinks
任何解决方案?
答案 0 :(得分:0)
您可以在restorationHandler
函数中添加类似下面的代码:
BOOL handled = [[RNFirebaseLinks instance] application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
if (!handled) {
handled = [RCTLinkingManager application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler];
}
return handled;
答案 1 :(得分:0)
回答这个问题有点晚了,但是目前建议的答案不起作用。它将无法从Firebase应用内消息中打开操作,因为从NO
返回的RNFirebaseLinks
将被RCTLinkingManager
覆盖,其中YES
是恢复处理程序。
如果遇到此问题,请尝试以下操作:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
BOOL handledLink = [[RNFirebaseLinks instance] application:application openURL:url options:options];
if (!handledLink) {
handledLink = [RCTLinkingManager application:application openURL:url options:options];
}
return handledLink;
}
- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray *))restorationHandler {
BOOL handleRestore = [[RNFirebaseLinks instance] application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
if (handleRestore) {
handleRestore = [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
}
return handleRestore;
}
我当前的设置和需求是react-navigation
v3和react-native-firebase
v5
答案 2 :(得分:0)
对我来说,解决方案是:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
if (url == nil) return false;
BOOL handled = [[RNFirebaseLinks instance]
application:application
openURL:url
options:options
] || [RCTLinkingManager
application:application
openURL:url
options:options
];
return handled;
}
- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray *))restorationHandler {
BOOL handled = [[RNFirebaseLinks instance]
application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler
] || [RCTLinkingManager
application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler
];
return handled;
}
react-native-firebase:5.5.6,react-navigation 3.X 启动应用程序时,无法将网址控制为nil会导致崩溃。