react-native - Linking.addEventListener 在本机反应中不起作用
问题描述
我已经成功实现了一个通用链接,可以在我的应用程序中打开特定页面(如果应用程序已关闭)。问题是,如果应用程序在后台运行,则不会调用 eventListener。这是代码:
import {Linking} from 'react-native';
export default class App extends React.Component {
async componentDidMount(){
Linking.addEventListener('url', this._handleOpenURL);
let url = await Linking.getInitialURL();
if (url) {
console.log('MOUNT GET INIT URL','initial url ' + url);
}
}
_handleOpenURL = (event) => {
console.log("in _handleOpenURL", event.url)
}
}
MOUNT GET INIT URL
成功登录到控制台。 in _handleOpenURL
从不记录。似乎互联网上的其他人也遇到了这个问题,但没有人回答。有谁知道该怎么做?
解决方案
@end
在 appdelegate.m中的最后一个之前添加:
// iOS 9.x or newer
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
return [RCTLinkingManager application:application openURL:url options:options];
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
{
return [RCTLinkingManager application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler];
}
推荐阅读
- c - 使用结构集中硬件抽象层使代码执行速度变慢
- dialogflow-es - Dialogflow 无法处理 @sys.date 的简写形式
- azure-devops - Azure cli:克隆管道
- c++ - 程序没有正确读取字符串
- python - 无法将值转换为 int python
- asp.net - ASP.net Webform 中的 Page_OnLoad 事件中的会话 ID 为空
- google-cloud-run - Cloud Run - 使用通配符子域的自定义域映射
- google-cloud-platform - 调整 GKE 以加快分配和分配 IP 给新服务的速度
- php - MapBox addLayer/addSource 不添加从 php 创建的 geoJson 的点
- sql-server - 在 SQL 中粉碎 XML 但交叉应用会添加不需要的记录