今天我们介绍一下app端的实现, 一直没写也是因为我觉得app端确实没啥可以写的.
它真的很简单.
我就基于RN + iOS一起回顾一下.
主要是两点.
一是universal link的配置!
这个网上讲这个的太多了我就找了一个感觉讲的还不错的给大家贴个链接 abhimuralidharan.medium.com/universal-l… (主要是因为懒)
二是 React Linking的使用
打开metamask
引入link和button
import { Button, Linking, } from 'react-native';
点击按钮通过链接打开metamask
<Button color="#fff" title="Go to Sign" onPress={() => { Linking.openURL( 'https://metamask.app.link/dapp/www.jobinleung.me/sign', ); }}> Sign </Button>
返回App
监听返回链接以及参数
const onAppWokUp = (event: {url: string}) => {
setInintUrl(event.url);
};
useEffect(() => {
Linking.getInitialURL().then(url => {
if (url) {
setInintUrl(url);
}
});
Linking.addEventListener('url', onAppWokUp);
return () => {
Linking.removeEventListener('url', onAppWokUp);
};
}, []);
就是这么简单 我把app端的代码也放到GitHub感兴趣的大家可以去瞧一瞧!