我试图拨打电话号码,如果用户在反应原生中刷电话图标。对于例如如果我的手机上有(999)-996-5432,那么当用户滑动图标时,应自动拨打此号码。下面是我的handleclick代码
export default class ServiceListDetails extends Component {
handleClick = (link) => {
Linking.canOpenURL(link).then(suppported => {
if (supported) {
Linking.openURL(link);
} else {
console.log('Don\'t know how to open URI: ' + link);
}
});
};
下面是我调用handleClick的代码:
return(
<Text style={styles.Address1}>{item.addr} </Text>
<View style={styles.phoneImg}>
<TouchableOpacity
onPress={() => { this.handleClick('tel:${item.phone}')}}>
<Image source={require('../images/Phone.png')} style={styles.actionImage}/>
</TouchableOpacity>
<Text style={styles.Address1}>{item.phone}</Text>
</View>
)
item.phone来自我的JSON文件。以下是我的JSON文件:
[
{
"id":"2",
"fk": 1,
"addr": "123 test drive, Ring road test",
"phone": "(999)-345-7896"
},
{
"id":"3",
"fk": 1,
"addr": "123 test drive, Test Road",
"phone": "(951)-765-2222"
}
]
我已经在iPhone上部署了该应用程序,并试图刷掉电话号码,但它没有做任何事情。我知道电话图标滑动不会在模拟器中工作。
任何帮助将不胜感激。
存在拼写错误(支持和支持)。解决这个问题,它会起作用
Linking.canOpenURL(link).then(suppported => {
if (supported) {