Swiftpack.co - Package - AfricasTalkingLtd/africastalking-swift

Africa's Talking

This SDK simplifies the integration of Africa's Talking APIs into your iOS apps. For better security, the SDK is split into two components: A server module that stores API keys, SIP credentials and other secrets. And a client module that runs in your app. This client module gets secrets from the server component (via RPC), and uses them to interact with the various APIs.

For instance, to send an SMS, the client with request a token from the server; The server will use it's API key to request a token from Africa's Talking on behalf of the client. It will then forward the token to the client which will use it to request the SMS API to send a text. All in a split second!


Your server application could be something like this:

/* On The Server (Node.js, Java, and all languages supported by gRPC.) */

const options = {
    apiKey: 'YOUR_API_KEY',         // Use sandbox API key for sandbox development
    username: 'YOUR_USERNAME',      // Use "sandbox" for sandbox development
const Server = require('africastalking/server');
const srv = new Server(options);
    privateKeyFile: fs.readFileSync('path/to/pk'),
    certChainFile: fs.readFileSync('path/to/cert/chain'),
    rootCertFile: fs.readFileSync('path/to/root/cert'),
    port: 35897,
    insecure: false,

And your iOS app:

/* On The Client (iOS) */

// Init SDK

// Get Service
let airtime = AfricasTalking.getAirtimeService()

// Use Service
let recipients = [
  ["phoneNumber": "+254718769882", "currencyCode": "KES", "amount": 332],
  ["phoneNumber": "0718769881", "currencyCode": "KES", "amount": 324 ]
airtime.send(to: recipients) {error, data in




npm install --save africastalking


repositories {
  maven {
    url  "http://dl.bintray.com/africastalking/java"
  compile 'com.africastalking:server:VERSION'

Or Maven (from http://dl.bintray.com/africastalking/java)


Client (iOS)

With Swift Package Manager

import PackageDescription

let package = Package(
    name: "YourApp"
    dependencies: [
        .package(url: "https://github.com/AfricastalkingLtd/africastalking-swift.git", from: "1.0.0"),
    targets: [
            name: "YourApp",
            dependencies: ["AfricasTalking",]


The following static methods are available in the africasTalking package to initialize the library:

  • initialize(host: String, port: Int, disableTls: Bool): Initialize the library.
  • getXXXService(): Get an instance to a given XXX service. e.g. .getSmsService(), .getPaymentService(), etc.


All methods take a Africastalking.Callback: (error: String?, data: JSON?) -> Void as the last parameter.


  • getUser(): Get user information.


  • send(to: String, amount: String): Send airtime to a phone number. Amount with currency code, e.g. USD 10

  • send(recipients: [[String: Any]]): Send airtime to a bunch of phone numbers. The keys in the recipients map are phone numbers while the values are airtime amounts ( e.g. KES 678).

For more information about status notification, please read http://docs.africastalking.com/airtime/callback


  • createCheckoutToken(phoneNumber: String): Create a checkout token.


  • send(message: String, to: [String], from: String?): Send a message

  • sendBulk(message: String, to: [String], from: String?): Send a message in bulk

  • sendPremium(message: String, keyword: String, linkId: String, to: [String], from: String?): Send a premium SMS

  • fetchMessages(lastReceivedId: Int?): Fetch your messages

  • fetchSubscriptions(lastReceivedId:Int?, shortCode: String, keyword: String): Fetch your premium subscription data

  • createSubscription(shortCode: String, keyword: String, phoneNumber: String): Create a premium subscription

For more information on:


  • checkout(request: CheckoutRequest): Initiate checkout(mobile, card or bank).

  • validateCheckout(request: CheckoutValidateRequest): Validate checkout (card or bank).

  • mobileB2C(productName: String, recipients: [Consumer]): Send money to consumer.

  • mobileB2B(productName: String, recipient: Business): Send money to business.


  • makeCall(from: String, to: [String]): Initiate an outbound call from your virtual number to some number(s)

  • queueStatus(phoneNumbers: String): Query call queue status

  • mediaUpload(url: String, phoneNumber: String): Upload media file


For more info, please visit https://www.africastalking.com


Stars: 0
Help us keep the lights on

Used By

Total: 0


1.0.0 - Dec 7, 2017

👏 🤔 👍