Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

React-Native-Twilio-Programmable-Voice initWithToken() and addEventListener('deviceReady') not working

$
0
0

TwilioVoice.initWithToken() returns that it has been initialized, but doesn't ready the device for incoming/outgoing calls. Even when passing in a random token into TwilioVoice.initWithToken(), it still returns true.

Here's the code I've been using:

import React, {Component} from 'react';import {  SafeAreaView,  StyleSheet,  ScrollView,  View,  Text,  StatusBar,  TouchableOpacity,} from 'react-native';import {  Header,  LearnMoreLinks,  Colors,  DebugInstructions,  ReloadInstructions,} from 'react-native/Libraries/NewAppScreen';import TwilioVoice from 'react-native-twilio-programmable-voice';export default class App extends Component {  state = {    twilioInited: false  };  getAuthToken = () => {    return fetch('serverurl', {       method: 'get',    })      .then(response => response.text())      .catch((error) => console.error(error));  }   getMicrophonePermission = () => {    const audioPermission = PermissionsAndroid.PERMISSIONS.RECORD_AUDIO;    return PermissionsAndroid.check(audioPermission).then(async result => {      if (!result) {        const granted = await PermissionsAndroid.request(audioPermission, {          title: 'Microphone Permission',          message: 'App needs access to you microphone '+'so you can talk with other users.',        });      }    });  }  initTwilio = async () => {     const token = await this.getAuthToken();    console.log ('Got auth token: '+ token);    if (Platform.OS === 'android') {      await this.getMicrophonePermission();    }    let success = await TwilioVoice.initWithToken(token);    console.log(isuccess);    TwilioVoice.addEventListener('deviceReady', () => {      this.setState({ twilioInited: true });      console.log('Device has been configured.');    });    TwilioVoice.addEventListener('deviceNotReady', () => {      console.log('Device not ready.');    });    if (Platform.OS === 'ios') { //required for ios      TwilioVoice.configureCallKit({          appName: 'callerid',      });      console.log('CallKit Configured');    }  };  makeCall = () => TwilioVoice.connect({ To: 'Alice' });  render() {    return (<View style={styles.container}><TouchableOpacity onPress={() => this.initTwilio()}><View><Text>Init Twilio!!</Text></View></TouchableOpacity><TouchableOpacity disabled={!this.state.twilioInited} onPress={() => this.makeCall()}><View><Text style={styles.highlight}>Ready to recieve calls: ({this.state.twilioInited ? 'ready' : 'not ready'})</Text></View></TouchableOpacity></View>    );  }}const styles = StyleSheet.create({  container: {    flex: 1,    justifyContent: 'center',    alignItems: 'center',    backgroundColor: '#F5FCFF',  },  highlight:{    fontWeight:'700',  }});

Followed all the instructions as specified in the Twilio Quickstart repositories.Using RN Version 0.63.Using RN-Twilio-Programmable-Voice version 3.0.0Using iOS 12.4 on iPhone XRApp running in foreground

Step to reproduce: Running normally


Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>