A Swift package for interacting with the SMS Activate API. This package provides an easy way to manage phone numbers for SMS-based verification services.
- Get account balance and cashback information
- Request a phone number for activation
- Get activation status
- Retrieve active activations
- Set activation status
- Get available operators for a given country
- Retrieve the list of all countries
- iOS 15.0+
- Swift 5.6+
Add the library to your project using Swift Package Manager:
- Open your project in Xcode.
- Go to File > Swift Packages > Add Package Dependency.
- Enter the repository URL
https://github.com/DeveloperZelentsov/SMSActivateAPI
for the SmsActivateAPI library and click Next. - Choose the latest available version and click Next.
- Select the target where you want to use SmsActivateAPI and click Finish.
First, import the SmsActivateAPI library in your Swift file:
import SmsHubAPI
To start using the library, create an instance of SmsActivateAPI with your API key:
let smsActivateAPI = SmsActivateAPI(apiKey: "your_api_key_here")
To get the account balance, call the getBalance(with state: BalanceState)
function:
do {
let balance = try await smsActivateAPI.getBalance(with: .balance)
print("Account balance: \(balance)")
} catch {
print("Error: \(error)")
}
To request a phone number, create a GetNumberRequest object and call the getNumber(request: GetNumberRequest)
function:
do {
let request = GetNumberRequest(service: "your_service_code", countryId: "your_country_id")
let (activationId, phoneNumber) = try await smsActivateAPI.getNumber(request: request)
print("Activation ID: \(activationId), Phone Number: \(phoneNumber)")
} catch {
print("Error: \(error)")
}
The waitForCode(id: Int, attempts: Int = 40, setStatusAfterCompletion: Bool = false)
function is an asynchronous method designed to simplify the process of waiting for an SMS code to be received for a specific activation. This function periodically checks the activation status until a code is received or a specified number of attempts has been reached.
do {
let activationId = 12345
let code = try await smsActivateAPI.waitForCode(id: activationId)
print("Received code: \(code)")
} catch {
print("Error: \(error)")
}
To get the activation status, call the getStatus(id: Int)
function:
do {
let activationId = 12345
let (status, code) = try await smsActivateAPI.getStatus(id: activationId)
print("Status: \(status), Code: \(String(describing: code))")
} catch {
print("Error: \(error)")
}
To get the list of active activations, call the getActiveActivations()
function:
do {
let activeActivations = try await smsActivateAPI.getActiveActivations()
print("Active activations: \(activeActivations)")
} catch {
print("Error: \(error)")
}
To set the activation status, create a SetStatusRequest object and call the setStatus(request: SetStatusRequest)
function:
do {
let activationId = 12345
let setStatus = SetStatus.ready
let request = SetStatusRequest(id: activationId, status: setStatus)
let response = try await smsActivateAPI.setStatus(request: request)
print("Status set response: \(response)")
} catch {
print("Error: \(error)")
}
To get available operators for a given country, call the getOperators(countryId: Int?)
function:
do {
let countryId = 1
let operators = try await smsActivateAPI.getOperators(countryId: countryId)
print("Available operators: \(operators)")
} catch {
print("Error: \(error)")
}
To get the list of all countries, call the getCountries()
function:
do {
let countries = try await smsActivateAPI.getCountries()
print("Countries: \(countries)")
} catch {
print("Error: \(error)")
}
For more information on the available methods and their parameters, refer to the ISmsActivateAPI protocol and the library's source code.
This project is released under the MIT License.