The access token generated by your server component is a jwt that contains a grant
for Programmable Voice, an identity
that you specify, and a time-to-live
that sets the lifetime of the generated access token. The default time-to-live
is 1 hour and is configurable up to 24 hours using the Twilio helper libraries.
In the iOS SDK the access token is used for the following:
- To make an outgoing call via
TwilioVoice.connect(...)
- To register or unregister for incoming notifications using VoIP Push Notifications via
TwilioVoice.registerWithAccessToken(...)
andTwilioVoice.unregisterWithAccessToken(...)
. Once registered, incoming notifications are handled via aTVOCallInvite
where you can choose to accept or reject the invite. When accepting the call an access token is not required. Internally theTVOCallInvite
has its own access token that ensures it can connect to our infrastructure.
As mentioned above, an access token will eventually expire. If an access token has expired, our infrastructure will return error TVOErrorAccessTokenExpired
/20104
via TVOCallDelegate
or a completion error when registering.
There are number of techniques you can use to ensure that access token expiry is managed accordingly:
- Always fetch a new access token from your access token server before making an outbound call.
- Retain the access token until getting a
TVOErrorAccessTokenExpired
/20104
error before fetching a new access token. - Retain the access token along with the timestamp of when it was requested so you can verify ahead of time whether the token has already expired based on the
time-to-live
being used by your server. - Prefetch the access token whenever the
UIApplication
, orUIViewController
associated with an outgoing call is created.