A Swift library that provides an easy-to-use interface for OnlineSim API services.
- Asynchronous API calls using Swift's async/await syntax
- Simple and straightforward usage
- Comprehensive protocol with all major OnlineSim API methods
- Unit tested for reliability
- 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/OnlineSimApi
for the OnlineSimApi 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 OnlineSimApi library in your Swift file:
import OnlineSimApi
To start using the library, create an instance of OnlineSimApi with your API key:
let onlineSimApi = OnlineSimApi(apiKey: "your_api_key_here")
To get the account balance, call the getBalance()
function:
do {
let balanceResponse = try await onlineSimApi.getBalance()
print("Account balance: \(balanceResponse.balance)")
} catch {
print("Error: \(error)")
}
To request a phone number, create a GetOnlineSimNumberRequest object and call the getNumber(with request: GetOnlineSimNumberRequest)
function:
do {
let request = GetOnlineSimNumberRequest(service: "your_service", country: 7)
let response = try await onlineSimApi.getNumber(with: request)
print("Operation ID: \(response.tzid), Phone Number: \(response.number)")
} catch {
print("Error: \(error)")
}
The waitForCode(operationId: 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 operation. This function periodically checks the operation status until a code is received or a specified number of attempts has been reached.
do {
let operationId = 12345
let code = try await onlineSimApi.waitForCode(operationId: operationId)
print("Received code: \(code)")
} catch {
print("Error: \(error)")
}
You can use other functions provided by the IOnlineSimApi protocol, such as getNumbersStats
, getState
, setOperationRevise
, and setOperationOk
, following the same pattern demonstrated in the examples above. Make sure to check the function parameters and expected return types in the protocol definition to understand how to use them properly.
For more information on the available methods and their parameters, refer to the IOnlineSimApi protocol and the library's source code.
This project is released under the MIT License.