- Getting Started
- Initialization
- Authorization
- Performing API Call
- Performing RingOut
- Sending SMS
- Subscription
- SDK Demos
- iOS 8.0+
- Xcode 7.0+
- Swift 2.0
The RingCentral Swift SDK is a CocoaPod written in Swift 2.0. CocoaPods is a dependency manager for Cocoa projects. To get started using the RingCentral-Swift SDK, we recommend you add it to your project using CocoaPods.
-
Install CocoaPods:
$ sudo gem install cocoapods
-
To integrate RingCentral Swift SDK into your Xcode project, navigate to the directory that contains your project (.xcworkspace) and create a new Podfile using
$ pod init
or open an existing one, then add the following lines:
platform :ios, '8.0' use_frameworks! target 'YourProjectName' do pod 'ringcentral' end
-
Then, run the following command to install the RingCentral-Swift SDK:
$ pod install
-
open
YourProjectName.xcworkscpace
in Xcode to begin coding.
You can integrate RingCentral Swift SDK into your project manually without using a dependency manager.
Drag the src
project into your own and add the resource as an Embedded Binary, as well as a Target Dependency and Linked Framework (under Build Phases) in order to build on the simulator and on a device.
Before you start, import the library into your project.
import ringcentral
RingCentral SDK is initiated in the following ways.
Sandbox:
var rcsdk = SDK(appKey: app_key, appSecret: app_secret, server: SDK.RC_SERVER_SANDBOX)
Production:
var rcsdk = SDK(appKey: app_key, appSecret: app_secret, server: SDK.RC_SERVER_PRODUCTION)
The app_key
and app_secret
should be read from a configuration file.
Depending on the stage of production, either SDK.RC_SERVER_SANDBOX
or SDK.RC_SERVER_PRODUCTION
will be used as the server
parameter.
To authorize the platform, extract the 'Platform' object:
var platform = rcsdk.getPlatform()
Once the platform is extracted, call:
platform.login(username: username, password: password)
{
(completion handler) in
}
or (to authorize with extension):
platform.login(username: username, ext: ext, password: password)
{
(completion handler) in
}
Caution: If no extension is specified, platform automitically refers extension 101 (default).
Currently all requests can be made through the following:
platform.get('/account/~/extension/~')
platform.post('/account/~/extension/~', body: [])
platform.put('/account/~/extension/~', body: [])
platform.delete('/account/~/extension/~', query: [])
Attach the following code as a completion handler (always) :
{
(apiresponse,apiexception) in
print("The response is:", apiresponse)
}
Returning 'data' into a Dictionary (JSON): This is handled by the ApiResponse class within the SDK. we can retrieve the dictionary as shown below
NSJSON Serialization handled by ApiResponse class :
NSJSONSerialization.JSONObjectWithData(data!, options: nil, error: &errors) as! NSDictionary
Retrieve the dictionary in your application as shown below :
apiresponse.getDict()
For readability of the data
print(apiresponse.getDict())
RingOut follows a two-legged style telecommunication protocol. The following method call is used to create a Ring Out.
platform.post("/account/~/extension/~/ringout", body :
[ "to": ["phoneNumber": "ToNumber"],
"from": ["phoneNumber": "FromNumber"],
"callerId": ["phoneNumber": "CallerId"],
"playPrompt": "true"
])
{
(completition handler)
}
The following method call is used to send a SMS.
platform.post("/account/~/extension/~/sms", body :
[ "to": [["phoneNumber": "18315941779"]],
"from": ["phoneNumber": "15856234190"],
"text": "Test"
])
{
(completition handler)
}
Create a subscription using the createSubscription method
var subscription = rcsdk.createSubscription()
To add Events to the Subscription Object:
subscription.addEvents(
[
"/restapi/v1.0/account/~/extension/~/presence",
"/restapi/v1.0/account/~/extension/~/message-store"
])
Register a Subscription:
subscription.register()
{
(completition handler)
}
Please keep in mind that due to limitations of PUBNUB library, which is synchronous, subscriptions may expire and must be re-created manually.
Login page: Insert app_key, app_secret, username, password in order to log in. This is generally done through a configuration file.
Phone page: Use the number pad to type the numbers you need. The Status Bar (initially shown as a red rectangle 'No Call') changes color accordingly. Allows the sending of SMS and Fax, along with the ability to make calls.
Log page: Shows implementation of the 'Call Log' along with the 'Message Log'.