Skip to content

anilkumarbp/ringcentral-swiftv2.0

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RingCentral Swift2.0 SDK ( Beta )

MIT licensed Gem Version


  1. Getting Started
  2. Initialization
  3. Authorization
  4. Performing API Call
  5. Performing RingOut
  6. Sending SMS
  7. Subscription
  8. SDK Demos


Requirements

  • iOS 8.0+
  • Xcode 7.0+
  • Swift 2.0

Getting Started

CocoaPods (recommended)

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.

  1. Install CocoaPods:

    $ sudo gem install cocoapods
  2. 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
  3. Then, run the following command to install the RingCentral-Swift SDK:

    $ pod install
  4. open YourProjectName.xcworkscpace in Xcode to begin coding.

If you do not Use CocoaPods, manually Add Subprojects

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.

Manually Install Framework

Initialization

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.

Authorization

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).


Performing API Call

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())

Performing RingOut

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)
    }

Sending SMS

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)
    }

Subscription

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.


SDK Demo : ( w.i.p )

Login page: Insert app_key, app_secret, username, password in order to log in. This is generally done through a configuration file.

Alt text

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.

Alt text

Log page: Shows implementation of the 'Call Log' along with the 'Message Log'.

Alt text

Packages

No packages published