📅  最后修改于: 2023-12-03 15:34:38.499000             🧑  作者: Mango
React Native CallKeep是一个React Native库,用于在iOS和Android设备中实现VoIP应用程序,包括呼入呼出,静音,通话保持和结束通话等功能。
使用npm进行安装:
npm install --save react-native-callkeep
<key>NSMicrophoneUsageDescription</key>
<string>Requesting access to use the microphone</string>
<key>NSVoIPUsageDescription</key>
<string>Requesting access to maintain a persistent voice connection</string>
在“AndroidManifest.xml”文件中添加以下权限和服务:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
<service
android:name="com.callkeep.BackgroundCallKeepService"
android:label="@string/app_name"
android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE">
<intent-filter>
<action android:name="android.telecom.ConnectionService" />
</intent-filter>
</service>
在React Native应用程序中导入CallKeep并将其添加到你的组件中。
import CallKeep from 'react-native-callkeep';
class App extends React.Component {
componentDidMount() {
const options = {
ios: {
appName: 'My App Name',
},
android: {
alertTitle: 'Permissions Required',
alertDescription: 'This application needs to access your phone accounts',
cancelButton: 'Cancel',
okButton: 'OK',
},
};
try {
await CallKeep.setup(options);
console.log('CallKeep setup successful');
} catch (err) {
console.log('CallKeep setup failed', err);
}
}
render() {
return (
<View>
<Text>Hello World!</Text>
</View>
);
}
}
CallKeep.displayIncomingCall('callUUID', 'number', 'Caller Name', 'callId', 'callId');
CallKeep.answerIncomingCall('callUUID');
CallKeep.endCall('callUUID');
CallKeep.setMutedCall('callUUID', true);
React Native CallKeep是一个强大的库,可以方便地为你的React Native应用程序添加呼入呼出电话的功能。此库在iOS和Android设备上都已经成功地测试过。