Native SDK
The Mercado Pago native SDK simplifies and secures the card payment process in Android and iOS applications. Select the technology you use and follow the steps to set up your development environment and start the payment flow securely.
Use the Mercado Pago native SDK to integrate payment methods into iOS applications. See below how to install and initialize the SDK.
Install SDK
Check below for the step-by-step instructions to install the SDK in your Swift project.
- In Swift Package Manager, click File > Add Packages.
- Paste the repository URL:
https://github.com/mercadopago/sdk-ios
. - Select the desired SDK version.
- Click Add Package to complete the installation.
Add dependencies
Import the SDK dependencies into your project by running the following code:
plain
import CoreMethods
Initialize SDK
After installing the SDK and adding the dependencies to your project, initialize the SDK at the beginning of the application's lifecycle. This ensures that all essential settings are defined before any payment operation.
To initialize the Mercado Pago library, you must use your credentialsCredentials, which are unique keys that identify your integration and are linked to the applicationApplication details you created, ensuring your project is developed with the best Mercado Pago security standards.
At this stage, you should use your Production Public Key, which can be accessed in the details of your application under Your integrations, under the section Production > Production credentials in the menu on the left side of the screen.
Copy the Public Key and include it in the code below. The initialization process varies depending on whether you use UIKit or SwiftUI.
import UIKit
import CoreMethods
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
let configuration = MercadoPagoSDK.Configuration(
publicKey: "YOUR-PUBLIC-KEY",
country: // Enter the country of your public key
)
MercadoPagoSDK.shared.initialize(configuration)
return true
}
}
import SwiftUI
import CoreMethods
@main
struct YourApp: App {
init() {
let configuration = MercadoPagoSDK.Configuration(
publicKey: "<YOUR-PUBLIC-KEY>",
country: "<Enter the country of your public key>",
locale: "en-US"
)
MercadoPagoSDK.shared.initialize(configuration)
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
The initialization parameters are listed in the table below.
Parameter | Type | Description | Required |
public_key | String | Public key used in the frontend to access information. You can access it through Your integrations > Application details > Production > Production credentials. | Required |
locale | String | Locale identifier (language and country). By default, the system's locale is used. | Optional |
country | Country | Enum that identifies the country where the Core Methods will be processed. Use the country code corresponding to your Public Key. See the documentation for your country's code. | Required |