TwilioVoiceSDK
Objective-C
@interface TwilioVoiceSDK : NSObject
Swift
class TwilioVoiceSDK : NSObject
TwilioVoiceSDK is the entry point to the Twilio Voice SDK. You can register for VoIP push notifications, make outgoing
Calls, receive Call invites and set audio device to use in a Call using this class.
-
@brief The current logging level used by the SDK.
@discussion The default logging level is
TVOLogLevelError.TwilioVoiceSDKand its components use NSLog internally.See
TVOLogLevelDeclaration
Objective-C
@property (class, nonatomic) TVOLogLevel logLevel;Swift
class var logLevel: TVOLogLevel { get set } -
@brief Specify reporting statistics to Insights.
@discussion Sending stats data to Insights is enabled by default.
Declaration
Objective-C
@property (class, nonatomic, assign, unsafe_unretained, readwrite, getter=isInsightsEnabled) BOOL insights;Swift
class var isInsightsEnabled: Bool { get set } -
@brief The edge value is a Twilio Edge name that corresponds to a geographic location of Twilio infrastructure that the client will connect to.
@discussion The default value
roamingautomatically selects an edge based on the latency between client and available edges.roamingrequires the upstream DNS to support RFC7871. See Global Low Latency requirements for more information.edgevalue must be specified before calling TwilioVoiceSDK.handleNotification().See the new Edge names for possible values.
Declaration
Objective-C
@property (class, nonatomic, copy, nonnull) NSString *edge;Swift
class var edge: String { get set } -
@brief The
TVOAudioDeviceused to record and playback audio in a Call.@discussion If you wish to provide your own
TVOAudioDevicethen you must set it before performing any other actions with the SDK like connecting to a Call. It is also possible to change the device when you are no longer connected to any Calls and have destroyed all other SDK objects.See
TVOAudioDeviceDeclaration
Objective-C
@property (class, nonatomic, strong, nonnull) id<TVOAudioDevice> audioDevice;Swift
class var audioDevice: any TVOAudioDevice { get set } -
@brief Returns the version of the SDK.
Declaration
Objective-C
+ (nonnull NSString *)sdkVersion;Swift
class func sdkVersion() -> StringReturn Value
The version of the SDK.
-
@brief Sets the logging level for an individual module.
See
TVOLogLevel
See
TVOLogModule
Declaration
Objective-C
+ (void)setLogLevel:(TVOLogLevel)logLevel module:(TVOLogModule)module;Swift
class func setLogLevel(_ logLevel: TVOLogLevel, module: TVOLogModule)Parameters
logLevelThe
<TVOLogLevel>level to be used by the module.moduleThe
<TVOLogModule>for which the logging level is to be set. -
@brief Retrieve the log level for a specific module in the TwilioVoice SDK.
Declaration
Objective-C
+ (TVOLogLevel)logLevelForModule:(TVOLogModule)module;Swift
class func logLevel(for module: TVOLogModule) -> TVOLogLevelParameters
moduleThe
TVOLogModulefor which the log level needs to be set.Return Value
The current log level for the specified module.
-
@brief Registers for Twilio VoIP push notifications.
@discussion Registering for push notifications is required to receive incoming call notification messages through Twilio’s infrastructure. Once successfully registered, the registered binding has a time-to-live(TTL) of 1 year. If the registered binding is inactive for 1 year it is deleted and push notifications to the registered identity will not succeed. However, whenever the registered binding is used to reach the registered identity the TTL is reset to 1 year. A successful registration will ensure that push notifications will arrive via the APNs for the lifetime of the registration device token provided by the APNs instance.
Your app must initialize PKPushRegistry with PushKit push type VoIP at the launch time. As mentioned in the PushKit guidelines, the system can’t deliver push notifications to your app until you create a PKPushRegistry object for VoIP push type and set the delegate. If your app delays the initialization of PKPushRegistry, your app may receive outdated PushKit push notifications, and if your app decides not to report the received outdated push notifications to CallKit, iOS may terminate your app.
If the registration is successful the completion handler will contain a
Null NSError. If the registration fails, the completion handler will have anonnull NSErrorwithUserInfostring describing the reason for failure.Registration Error Error Code Description TVOErrorAccessTokenInvalidError 20101 Twilio was unable to validate your Access Token TVOErrorAccessTokenHeaderInvalidError 20102 Invalid Access Token header TVOErrorAccessTokenIssuerInvalidError 20103 Invalid Access Token issuer or subject TVOErrorAccessTokenExpiredError 20104 Access Token has expired or expiration date is invalid TVOErrorAccessTokenNotYetValidError 20105 Access Token not yet valid TVOErrorAccessTokenGrantsInvalidError 20106 Invalid Access Token grants TVOErrorExpirationTimeExceedsMaxTimeAllowedError 20157 Expiration Time in the Access Token Exceeds Maximum Time Allowed TVOErrorAccessForbiddenError 20403 Forbidden. The account lacks permission to access the Twilio API TVOErrorBadRequestError 31400 Bad Request. The request could not be understood due to malformed syntax TVOErrorForbiddenError 31403 Forbidden. The server understood the request, but is refusing to fulfill it TVOErrorNotFoundError 31404 Not Found. The server has not found anything matching the request TVOErrorRequestTimeoutError 31408 Request Timeout. A request timeout occurred TVOErrorConflictError 31409 Conflict. The request could not be processed because of a conflict in the current state of the resource. Another request may be in progress TVOErrorUpgradeRequiredError 31426 Upgrade Required. This error is raised when an HTTP 426 response is received. The reason for this is most likely because of an incompatible TLS version. To mitigate this, you may need to upgrade the OS or download a more recent version of the SDK. TVOErrorTooManyRequestsError 31429 Too Many Requests. Too many requests were sent in a given amount of time TVOErrorInternalServerError 31500 Internal Server Error. The server could not fulfill the request due to some unexpected condition TVOErrorBadGatewayError 31502 Bad Gateway. The server is acting as a gateway or proxy, and received an invalid response from a downstream server while attempting to fulfill the request TVOErrorServiceUnavailableError 31503 Service Unavailable. The server is currently unable to handle the request due to a temporary overloading or maintenance of the server TVOErrorGatewayTimeoutError 31504 Gateway Timeout. The server, while acting as a gateway or proxy, did not receive a timely response from an upstream server TVOErrorTokenAuthenticationRejected 51007 Token authentication is rejected by authentication service TVOErrorRegistrationError 31301 Registration failed. Look at [error localizedFailureReason] for details Insights
Group Name Event Name Description Since version registration registration Registration is successful 3.0.0-beta3 registration registration-error Registration failed 3.0.0-beta3 ** An example of using the registration API **
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type { [TwilioVoiceSDK registerWithAccessToken:accessToken deviceToken:credentials.token completion:^(NSError *error) { if(error != nil) { NSLog("Failed to register for incoming push: %@\n\t - reason: %@", [error localizedDescription], [error localizedFailureReason]); } else { NSLog("Registration successful"); } }];The maximum number of characters for the identity provided in the token is 121. The identity may only contain alpha-numeric and underscore characters. Other characters, including spaces, or exceeding the maximum number of characters, will result in not being able to place or receive calls.
To specify a home region where your data is stored, use the
twrspecifier in the access token header as the example below:{ "alg": "HS256", "typ": "JWT", "cty": "twilio-fpa;v=1", "twr": "au1" } This can also be done by using the Twilio helper libraries when generating the access token. Here is an example of using the Twilio Node.js helper library:const accessToken = new twilio.jwt.AccessToken( credentials.accountSid, credentials.apiKeySid, credentials.apiKeySecret, { identity, ttl, region: ‘au1’, }, );
Note that the home region configuration is only scoped to one registration request. - parameter: accessToken Twilio Access Token. - parameter: deviceToken The push registry token raw data for Apple VoIP Service. - parameter: completion Callback block to receive the result of the registration.Declaration
Objective-C
+ (void)registerWithAccessToken:(nonnull NSString *)accessToken deviceToken:(nonnull NSData *)deviceToken completion: (nullable void (^)(NSError *_Nullable))completion;Swift
class func register(withAccessToken accessToken: String, deviceToken: Data) async throws -
@brief Unregisters from Twilio VoIP push notifications.
@discussion Call this method when you no longer want to receive push notifications for incoming Calls.
If the unregistration is successful the completion handler will contain a
Null NSError. If the unregistration fails, the completion handler will have anonnull NSErrorwithUserInfostring describing the reason for failure.Registration Error Error Code Description TVOErrorAccessTokenInvalidError 20101 Twilio was unable to validate your Access Token TVOErrorAccessTokenHeaderInvalidError 20102 Invalid Access Token header TVOErrorAccessTokenIssuerInvalidError 20103 Invalid Access Token issuer or subject TVOErrorAccessTokenExpiredError 20104 Access Token has expired or expiration date is invalid TVOErrorAccessTokenNotYetValidError 20105 Access Token not yet valid TVOErrorAccessTokenGrantsInvalidError 20106 Invalid Access Token grants TVOErrorExpirationTimeExceedsMaxTimeAllowedError 20157 Expiration Time in the Access Token Exceeds Maximum Time Allowed TVOErrorAccessForbiddenError 20403 Forbidden. The account lacks permission to access the Twilio API TVOErrorBadRequestError 31400 Bad Request. The request could not be understood due to malformed syntax TVOErrorForbiddenError 31403 Forbidden. The server understood the request, but is refusing to fulfill it TVOErrorNotFoundError 31404 Not Found. The server has not found anything matching the request TVOErrorRequestTimeoutError 31408 Request Timeout. A request timeout occurred TVOErrorConflictError 31409 Conflict. The request could not be processed because of a conflict in the current state of the resource. Another request may be in progress TVOErrorUpgradeRequiredError 31426 Upgrade Required. This error is raised when an HTTP 426 response is received. The reason for this is most likely because of an incompatible TLS version. To mitigate this, you may need to upgrade the OS or download a more recent version of the SDK TVOErrorTooManyRequestsError 31429 Too Many Requests. Too many requests were sent in a given amount of time TVOErrorInternalServerError 31500 Internal Server Error. The server could not fulfill the request due to some unexpected condition TVOErrorBadGatewayError 31502 Bad Gateway. The server is acting as a gateway or proxy, and received an invalid response from a downstream server while attempting to fulfill the request TVOErrorServiceUnavailableError 31503 Service Unavailable. The server is currently unable to handle the request due to a temporary overloading or maintenance of the server TVOErrorGatewayTimeoutError 31504 Gateway Timeout. The server, while acting as a gateway or proxy, did not receive a timely response from an upstream server TVOErrorTokenAuthenticationRejected 51007 Token authentication is rejected by authentication service TVOErrorRegistrationError 31301 Registration failed. Look at [error localizedFailureReason] for details Insights
Group Name Event Name Description Since version registration unregistration Unregistration is successful 3.0.0-beta3 registration unregistration-error Unregistration failed 3.0.0-beta3 ** An example of using the unregistration API **
[TwilioVoiceSDK unregisterWithAccessToken:accessToken deviceToken:deviceToken completion:^(NSError *error) { if(error != nil) { NSLog("Failed to unregister for incoming push: %@\n\t - reason: %@", [error localizedDescription], [error localizedFailureReason]); } else { NSLog("Unregistration successful"); } }];The maximum number of characters for the identity provided in the token is 121. The identity may only contain alpha-numeric and underscore characters. Other characters, including spaces, or exceeding the maximum number of characters, will result in not being able to place or receive calls.
To specify a home region where your data is stored, use the
twrspecifier in the access token header as the example below:{ "alg": "HS256", "typ": "JWT", "cty": "twilio-fpa;v=1", "twr": "au1" } This can also be done by using the Twilio helper libraries when generating the access token. Here is an example of using the Twilio Node.js helper library:const accessToken = new twilio.jwt.AccessToken( credentials.accountSid, credentials.apiKeySid, credentials.apiKeySecret, { identity, ttl, region: ‘au1’, }, );
Note that the home region configuration is only scoped to one registration request. - parameter: accessToken Twilio Access Token. - parameter: deviceToken The push registry token raw data for Apple VoIP Service. - parameter: completion Callback block to receive the result of the unregistration.Declaration
Objective-C
+ (void)unregisterWithAccessToken:(nonnull NSString *)accessToken deviceToken:(nonnull NSData *)deviceToken completion: (nullable void (^)(NSError *_Nullable))completion;Swift
class func unregister(withAccessToken accessToken: String, deviceToken: Data) async throws
-
@brief Processes an incoming VoIP push notification payload.
@discussion This method will synchronously process call notification payload and call the provided delegate on the same dispatch queue.
@discussion If you are specifying an edge value via the
TwilioVoiceSDK.edgeproperty you must do so before calling this method.Twilio sends a
callnotification via Apple VoIP Service. The notification type is encoded in the dictionary with the keytwi_message_typeand the valuetwilio.voice.call.A
callnotification is sent when someone wants to reach the registeredidentity. Passing acallnotification into this method will result in acallInviteReceived:callback with a<TVOCallInvite>object and returnYES.To ensure that a cancellation is reported via the [TVONotificationDelegate cancelledCallInviteReceived:error:] callback, the TVOCallInvite must be retained until the call is accepted or rejected.
Insights
Group Name Event Name Description Since version connection incoming Incoming call notification received 3.0.0-preview1 connection listen Reported when an attempt to listen for cancellations is made 5.0.0 connection listening Reported when an attempt to listen for cancellations has succeeded 5.0.0 connection cancel Reported when a cancellation has been reported 5.0.0 connection listening-error Reported when an attempt to listen for a cancellation has failed 5.0.0 registration unsupported-cancel-message-error Reported when a “cancel” push notification is processed by the SDK. This version of the SDK does not support “cancel” push notifications 5.0.0 ** An example of using the handleNotification API **
@interface CallViewController () <PKPushRegistryDelegate, TVONotificationDelegate, TVOCallDelegate, ... > // property declarations @end @implementation CallViewController // ViewController setup and other code ... #pragma mark - PKPushRegistryDelegate - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type { NSLog(@"Received incoming push: %@", payload.dictionaryPayload); if ([type isEqualToString:PKPushTypeVoIP]) { if (![TwilioVoiceSDK handleNotification:payload.dictionaryPayload delegate:self]) { NSLog(@"The push notification was not a Twilio Voice push notification"); } } } #pragma mark - TVONotificationDelegate methods - (void)callInviteReceived:(TVOCallInvite *)callInvite { // handle call invite } - (void)cancelledCallInviteReceived:(TVOCancelledCallInvite *)cancelledCallInvite { // handle cancelled call invite } @endSee
TVONotificationDelegate
Declaration
Objective-C
+ (BOOL)handleNotification:(nonnull NSDictionary *)payload delegate:(nonnull id<TVONotificationDelegate>)delegate delegateQueue:(nullable dispatch_queue_t)delegateQueue;Swift
class func handleNotification(_ payload: [AnyHashable : Any], delegate: any TVONotificationDelegate, delegateQueue: dispatch_queue_t?) -> BoolParameters
payloadPush notification payload.
delegateA
<TVONotificationDelegate>to receive incoming push notification callbacks.delegateQueueThe queue where the
[TVONotificationDelegate cancelledCallInviteReceived:error:]method will invoked. By default the main dispatch queue will be used.Return Value
A BOOL value that indicates whether the payload is a valid notification sent by Twilio.
-
@brief Processes an incoming VoIP push notification payload.
@discussion This method will synchronously process call notification payload and call the provided delegate on the same dispatch queue.
@discussion If you are specifying an edge value via the
TwilioVoiceSDK.edgeproperty you must do so before calling this method.Twilio sends a
callnotification via Apple VoIP Service. The notification type is encoded in the dictionary with the keytwi_message_typeand the valuetwilio.voice.call.A
callnotification is sent when someone wants to reach the registeredidentity. Passing acallnotification into this method will result in acallInviteReceived:callback with a<TVOCallInvite>object and returnYES.To ensure that a cancellation is reported via the [TVONotificationDelegate cancelledCallInviteReceived:error:] callback, the TVOCallInvite must be retained until the call is accepted or rejected.
Insights
Group Name Event Name Description Since version connection incoming Incoming call notification received 3.0.0-preview1 connection listen Reported when an attempt to listen for cancellations is made 5.0.0 connection listening Reported when an attempt to listen for cancellations has succeeded 5.0.0 connection cancel Reported when a cancellation has been reported 5.0.0 connection listening-error Reported when an attempt to listen for a cancellation has failed 5.0.0 registration unsupported-cancel-message-error Reported when a “cancel” push notification is processed by the SDK. This version of the SDK does not support “cancel” push notifications 5.0.0 ** An example of using the handleNotification API **
@interface CallViewController () <PKPushRegistryDelegate, TVONotificationDelegate, TVOCallDelegate, TVOCallMessageDelegate ... > // property declarations @end @implementation CallViewController // ViewController setup and other code ... #pragma mark - PKPushRegistryDelegate - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type { NSLog(@"Received incoming push: %@", payload.dictionaryPayload); if ([type isEqualToString:PKPushTypeVoIP]) { if (![TwilioVoiceSDK handleNotification:payload.dictionaryPayload delegate:self callMessageDelegate:self]) { NSLog(@"The push notification was not a Twilio Voice push notification"); } } } #pragma mark - TVONotificationDelegate methods - (void)callInviteReceived:(TVOCallInvite *)callInvite { // handle call invite } - (void)cancelledCallInviteReceived:(TVOCancelledCallInvite *)cancelledCallInvite { // handle cancelled call invite } @endSee
TVONotificationDelegate
Declaration
Objective-C
+ (BOOL)handleNotification:(nonnull NSDictionary *)payload delegate:(nonnull id<TVONotificationDelegate>)delegate delegateQueue:(nullable dispatch_queue_t)delegateQueue callMessageDelegate: (nullable id<TVOCallMessageDelegate>)callMessageDelegate;Swift
class func handleNotification(_ payload: [AnyHashable : Any], delegate: any TVONotificationDelegate, delegateQueue: dispatch_queue_t?, callMessageDelegate: (any TVOCallMessageDelegate)?) -> BoolParameters
payloadPush notification payload.
delegateA
<TVONotificationDelegate>to receive incoming push notification callbacks.delegateQueueThe queue where the
[TVONotificationDelegate cancelledCallInviteReceived:error:]method will invoked. By default the main dispatch queue will be used.callMessageDelegateThe
<TVOCallMessageDelegate>for<TVOCallMessage>related updates that are raised to theTVOCallInvite.Return Value
A BOOL value that indicates whether the payload is a valid notification sent by Twilio.
-
@brief Make an outgoing Call.
@discussion This method is guaranteed to return a
<TVOCall>object. It’s possible for the returned Call to either succeed or fail to connect.If you are specifying an edge value via the
TwilioVoiceSDK.edgeproperty you must do so before calling this method.The
<TVOCallDelegate>will receive the Call state update callbacks. The callbacks are listed here.Callback Name Description Since version call:didFailToConnectWithError The call failed to connect. An NSErrorobject provides details of the root cause.3.0.0-preview1 callDidStartRinging Emitted once before the callDidConnectcallback when the callee is being alerted of a Call.3.0.0-preview2 callDidConnect The Call has connected. 3.0.0-preview1 call:didDisconnectWithError The Call was disconnected. If the Call ends due to an error the NSErroris non-null. If the call ends normallyNSErroris nil.3.0.0-preview1 If connect fails,
call:didFailToConnectWithErrororcall:didDisconnectWithErrorcallback is raised with anNSErrorobject.[error localizedDescription],[error localizedFailureReason]and[error code]provide details of the failure.If any authentication error occurs then the SDK will receive one of the following errors.
Authentication Errors Error Code Description TVOErrorAccessTokenInvalidError 20101 Twilio was unable to validate your Access Token TVOErrorAccessTokenHeaderInvalidError 20102 Invalid Access Token header TVOErrorAccessTokenIssuerInvalidError 20103 Invalid Access Token issuer or subject TVOErrorAccessTokenExpiredError 20104 Access Token has expired or expiration date is invalid TVOErrorAccessTokenNotYetValidError 20105 Access Token not yet valid TVOErrorAccessTokenGrantsInvalidError 20106 Invalid Access Token grants TVOErrorAuthFailureCodeError 20151 Twilio failed to authenticate the client TVOErrorExpirationTimeExceedsMaxTimeAllowedError 20157 Expiration Time in the Access Token Exceeds Maximum Time Allowed TVOErrorAccessForbiddenError 20403 Forbidden. The account lacks permission to access the Twilio API TVOErrorApplicationNotFoundError 21218 Invalid ApplicationSid If any connection fails because of any other error then the SDK will receive one of the following errors.
Connection Errors Error Code Description TVOErrorConnectionError 31005 Connection error TVOErrorCallCancelledError 31008 Call Cancelled TVOErrorTransportError 31009 Transport error TVOErrorMalformedRequestError 31100 Malformed request TVOErrorAuthorizationError 31201 Authorization error TVOErrorBadRequestError 31400 Bad Request TVOErrorForbiddenError 31403 Forbidden TVOErrorNotFoundError 31404 Not Found TVOErrorRequestTimeoutError 31408 Request Timeout TVOErrorTemporarilyUnavailableError 31480 Temporarily Unavailable TVOErrorCallDoesNotExistError 31481 Call/Transaction Does Not Exist TVOErrorAddressIncompleteError 31484 The phone number is malformed TVOErrorBusyHereError 31486 Busy Here TVOErrorRequestTerminatedError 31487 Request Terminated TVOErrorInternalServerError 31500 Internal Server Error TVOErrorBadGatewayError 31502 Bad Gateway TVOErrorServiceUnavailableError 31503 Service Unavailable TVOErrorGatewayTimeoutError 31504 Gateway Timeout TVOErrorDNSResolutionError 31530 DNS Resolution Error TVOErrorDeclineError 31603 Decline TVOErrorDoesNotExistAnywhereError 31604 Does Not Exist Anywhere TVOErrorSignalingConnectionDisconnectedError 53001 Signaling connection disconnected TVOErrorMediaClientLocalDescFailedError 53400 Client is unable to create or apply a local media description TVOErrorMediaServerLocalDescFailedError 53401 Server is unable to create or apply a local media description TVOErrorMediaClientRemoteDescFailedError 53402 Client is unable to apply a remote media description TVOErrorMediaServerRemoteDescFailedError 53403 Server is unable to apply a remote media description TVOErrorMediaNoSupportedCodecError 53404 No supported codec TVOErrorMediaConnectionError 53405 Media connection failed TVOMediaDtlsTransportFailedErrorCode 53407 Media connection failed due to DTLS handshake failure Insights
Group Name Event Name Description Since version connection outgoing Outgoing call is made 3.0.0-beta2 settings codec negotiated selected codec is received and remote SDP is set 5.1.1 If connection fails then an error event will be published.
Group Name Event Name Description Since version connection error error description 3.0.0-beta2 ** An example of using the connectWithAccessToken:delegate: API **
@interface CallViewController () <TVOCallDelegate, ... > // property declarations @end @implementation CallViewController // ViewController setup and other code ... - (void)makeCall:(NSString*)accessToken self.call = [TwilioVoiceSDK connectWithAccessToken:accessToken delegate:self]; } #pragma mark - TVOCallDelegate - (void)callDidStartRinging:(TVOCall *)call { NSLog(@"Call is ringing at called party %@", call.to); } - (void)call:(TVOCall *)call didFailToConnectWithError:(NSError *)error { NSLog("Failed to Connect the Call: %@\n\t - reason: %@", [error localizedDescription], [error localizedFailureReason]); } - (void)call:(TVOCall *)call didDisconnectWithError:(NSError *)error { if (error) { NSLog(@"Call disconnected with error: %@", error); } else { NSLog(@"Call disconnected"); } } - (void)callDidConnect:(TVOCall *)call { NSLog(@"Call connected."); } @endThe maximum number of characters for the identity provided in the token is 121. The identity may only contain alpha-numeric and underscore characters. Other characters, including spaces, or exceeding the maximum number of characters, will result in not being able to place or receive calls.
To specify a home region where your data is stored, use the
twrspecifier in the access token header as the example below:{ "alg": "HS256", "typ": "JWT", "cty": "twilio-fpa;v=1", "twr": "au1" } This can also be done by using the Twilio helper libraries when generating the access token. Here is an example of using the Twilio Node.js helper library:const accessToken = new twilio.jwt.AccessToken( credentials.accountSid, credentials.apiKeySid, credentials.apiKeySecret, { identity, ttl, region: ‘au1’, }, );
Note that the home region configuration is only scoped to one call. - parameter: accessToken The access token. - parameter: delegate A `<TVOCallDelegate>` to receive Call state updates. - returns: A `<TVOCall>` object. - see: TVOCall - see: TVOCallDelegateDeclaration
Objective-C
+ (nonnull TVOCall *)connectWithAccessToken:(nonnull NSString *)accessToken delegate: (nonnull id<TVOCallDelegate>)delegate;Swift
class func connect(withAccessToken accessToken: String, delegate: any TVOCallDelegate) -> TVOCall -
@brief Make an outgoing Call.
@discussion This method is guaranteed to return a
<TVOCall>object. It’s possible for the returned Call to either succeed or fail to connect. Use the<TVOConnectOptions>builder to specify Call parameters and UUID.@discussion If you are specifying an edge value via the
TwilioVoiceSDK.edgeproperty you must do so before calling this method.The
<TVOCallDelegate>will receive the Call state update callbacks. The callbacks are same asconnectWithAccessToken:delegate:API.If connect fails,
call:didFailToConnectWithErrororcall:didDisconnectWithErrorcallback is raised with anNSErrorobject.[error localizedDescription],[error localizedFailureReason]and[error code]provide details of the failure. The error codes are same asconnectWithAccessToken:delegate:API.Insights
Group Name Event Name Description Since version connection outgoing Outgoing call is made 3.0.0-beta2 If connection fails then an error event will be published.
Group Name Event Name Description Since version connection error error description 3.0.0-beta2 ** An example of using the connectWithAccessToken:delegate API **
@interface CallViewController () <TVOCallDelegate, ... > // property declarations @end @implementation CallViewController // ViewController setup and other code ... - (void)makeCall:(NSString *)accessToken uuid:(NSString *)uuid to:(NSString *)phoneNumber NSMutableDictionary *params = [NSMutableDictionary dictionary]; if ([to length] > 0) { params[@"Mode"] = @"Voice"; params[@"PhoneNumber"] = phoneNumber; } TVOConnectOptions *connectOptions = [TVOConnectOptions optionsWithAccessToken:accessToken block:^(TVOConnectOptionsBuilder *builder) { builder.params = params; builder.uuid = uuid; }]; self.call = [TwilioVoiceSDK connectWithOptions:connectOptions delegate:self]; } #pragma mark - TVOCallDelegate - (void)callDidStartRinging:(TVOCall *)call { NSLog(@"Call is ringing at called party %@", call.to); } - (void)call:(TVOCall *)call didFailToConnectWithError:(NSError *)error { NSLog("Failed to Connect the Call: %@\n\t - reason: %@", [error localizedDescription], [error localizedFailureReason]); } - (void)call:(TVOCall *)call didDisconnectWithError:(NSError *)error { if (error) { NSLog(@"Call disconnected with error: %@", error); } else { NSLog(@"Call disconnected"); } } - (void)callDidConnect:(TVOCall *)call { NSLog(@"Call connected."); } @endTo specify a home region where your data is stored, use the
twrspecifier in the access token header as the example below:{ "alg": "HS256", "typ": "JWT", "cty": "twilio-fpa;v=1", "twr": "au1" } This can also be done by using the Twilio helper libraries when generating the access token. Here is an example of using the Twilio Node.js helper library:const accessToken = new twilio.jwt.AccessToken( credentials.accountSid, credentials.apiKeySid, credentials.apiKeySecret, { identity, ttl, region: ‘au1’, }, );
Note that the home region configuration is only scoped to one call. - parameter: options The connect options. - parameter: delegate A `<TVOCallDelegate>` to receive Call state updates. - returns: A `<TVOCall>` object. - see: TVOCall - see: TVOCallDelegate - see: TVOConnectOptionsDeclaration
Objective-C
+ (nonnull TVOCall *)connectWithOptions:(nonnull TVOConnectOptions *)options delegate:(nonnull id<TVOCallDelegate>)delegate;Swift
class func connect(with options: TVOConnectOptions, delegate: any TVOCallDelegate) -> TVOCall -
@brief Run a preflight test.
See
TVOPreflight
See
TVOPreflightDelegate
Declaration
Objective-C
+ (nonnull TVOPreflightTest *) runPreflightTestWithAccessToken:(nonnull NSString *)accessToken delegate:(nonnull id<TVOPreflightDelegate>)delegate;Swift
class func runPreflightTest(withAccessToken accessToken: String, delegate: any TVOPreflightDelegate) -> TVOPreflightTestParameters
accessTokenThe access token.
delegateA
<TVOPreflightDelegate>to receive preflight test updates.Return Value
A
<TVOPreflightTest>object. -
@brief Run a preflight test.
See
TVOPreflight
See
TVOPreflightDelegate
See
TVOPreflightOptions
Declaration
Objective-C
+ (nonnull TVOPreflightTest *) runPreflightTestWithOptions:(nonnull TVOPreflightOptions *)options delegate:(nonnull id<TVOPreflightDelegate>)delegate;Swift
class func runPreflightTest(with options: TVOPreflightOptions, delegate: any TVOPreflightDelegate) -> TVOPreflightTestParameters
optionsThe preflight test options.
delegateA
<TVOPreflightDelegate>to receive preflight test updates.Return Value
A
<TVOPreflightTest>object. -
Unavailable
TwilioVoiceSDK cannot be instantiated directly.
Undocumented
Declaration
Objective-C
- (null_unspecified instancetype)init __attribute__((unavailable("TwilioVoiceSDK cannot be instantiated directly.")));