SDK Native - Client-side - Mercado Pago Developers

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.

  1. In Swift Package Manager, click File > Add Packages.
  2. Paste the repository URL: https://github.com/mercadopago/sdk-ios.
  3. Select the desired SDK version.
  4. 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.

The SDK must be initialized only once when the application starts. To ensure correct operation, make a call to initialize() before using any other SDK functionality.

To initialize the Mercado Pago library, you must use your credentialsUnique access keys that we use to identify an integration in your account, linked to your application. For more information, see the link below.Credentials, which are unique keys that identify your integration and are linked to the applicationEntity registered in Mercado Pago that acts as an identifier for managing your integrations. For more information, see the link below.Application details you created, ensuring your project is developed with the best Mercado Pago security standards.

At this stage, you should use your Production Public KeyPublic key used in the frontend to access information. You can access it through Your integrations > Application details > Production > Production credentials., 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.

Cómo acceder a las credenciales a través de Tus Integraciones

If you are developing for someone else, you may access the credentials of applications you do not manage. See Share credentials for more information.

Copy the Public KeyPublic key used in the frontend to access information. You can access it through Your integrations > Application details > Production > Production credentials. 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.

ParameterTypeDescriptionRequired
public_keyStringPublic key used in the frontend to access information. You can access it through Your integrations > Application details > Production > Production credentials.Required
localeStringLocale identifier (language and country). By default, the system's locale is used.Optional
countryCountryEnum 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