Learn how to use the RingCentral SDK for Swift. Click the "Start Tutorial" button below to begin.
Start TutorialThis tutorial shows you how to build an iOS app and use the RingCentral Swift SDK to read call-log data from a RingCentral account then display the information on the screen.
You also have to create a RingCentral app with the "Read Call Log" permission. And retrieve the AppKey and AppSecret for using in this application.
Create a Single View app and give it a name “Call Analytics”.
Open Terminal window and browse to the “Call Analytics” folder and run the following command
$ brew install carthage
If you already had carthage installed, you may want to update with the latest version
$ brew update carthage
Create a "Carthage" file under the "Call Analytics" folder and copy/paste the following line to the file
github "ringcentral/ringcentral-swift"
Now in Terminal window, run the command below:
$ carthage update --platform iOS
Open the iOS project in XCode and goto the project settings. Select the "General" tab and from the “Embedded Binaries” section, click the + button and browse to the “Carthage/Build/iOS” folder under the project and add the frameworks to the project as shown below.
Add a new file named “Credentials.swift” to the project. And specify the RingCentral AppKey and AppSecret.
Open the AppDelegate.swift file. Define a RingCentral client instance and initialize it with the AppKey and AppSecret.
If your RingCentral app is in production, change the production flag to "true"
rc = RestClient(appKey: Configs.AppKey, appSecret: Configs.AppSecret, production: true)
We need a login view for users to enter their login credentials for login to their own RingCentral account.
Open the Main.storyboard then select the default View Controller and drag and drop a Navigation Bar and a bar button as shown below
Then drag and drop a view container (UIView) to the main view, and add 3 text fields (UITextField) as shown below
Now drag and drop another view container (UIView) to the main view, and add a button (UIButton) as shown below
Now click the Assistant button in the Xcode toolbar and connect the UIs to code
The login button is the right button on the Navigation bar.
The "Call Logs" button is the button inside the menu button form.
Inside the function, we implement code to login and logout. And we toggle the view between login form and menu button form accordingly.
To login RingCentral account, we call the authorize()
function passing the username, password and the extension if it is provided.
If login is successful, we toggle the view to show the menu button view and change the right navigation bar button text to "Logout".
To logout, we call the revoke()
function and reset the access token, then toggle the view to show the login form and change the right navigation bar button text to "Login".
We create a new file and select the Cocoa Touch class type and name it CallInfoViewController
Then we open the Main.storyboard then drag and drop a new View Controller to the storyboard
Now, click the Identity inspector then select the CallInfoViewController
class and specify the Identity Storyboard ID as “calllogview”
We create a navigation bar
We create an input form, where we define UI components for users to specify reading parameters.
And we create an output view for displaying call-log data.
Now click the Assistant button in the Xcode toolbar and connect the UIs to code
The valid values of input parameters are specified in RingCentral API reference.
When a user specifies the parameters, we collect the inputs and keep them in the calllogReq
variable.
ReadBtnClicked
functionWhen a user clicks the "Read" button, we call the calllog()
function to fetch the call log data from RingCentral server
If the call was successful and we receive the response, we copy the records array to the callLogRecords
array and populate the data to the list view.
We parse each record and display record information on the list.
We also analyze call types and display statistic numbers.