Setup
If you do not decommission your app versions that include the older SDK versions or force upgrade your app with the updated certificates by the expiration date, 100% of your customer traffic will fail.
Requirements
- Xcode 16.2+
- A minimum deployment target of iOS 16.0
- Swift 5.10+ (or Objective-C)
It goes without saying, but we’ll say it anyway: we always recommend using the latest versions of our SDKs. In order to communicate securely with the Braintree gateway, you must use at least version 4.10.0 of the iOS SDK.
Installation
There are multiple ways to include Braintree in your project. See the Installation section of our README.
Setup for app context switching
In order to use the Venmo flow, your application must be set up for Universal Links. You will need to use a custom path dedicated to Braintree app switch returns. This URL must also be added to your app association file with wildcards allowed to ensure we receive the expected data on return.
An example apple-app-site-association may look like the following:
- JSON
{
"applinks": {
"details": [
{
"appID": "com.your-app-id",
"paths": [
"/braintree-payments/*"
]
}
]
}
}Handle app context switching
Then pass the payment authorization URL to Braintree for finalization.
If you’re using SwiftUI, you must add the onOpenURL(perform:) modifier to your ContentView, and then call BTAppContextSwitcher's handleOpen(url:) method.
- Swift
.onOpenURL { url in
BTAppContextSwitcher.sharedInstance.handleOpen(url)
}If you're using UISceneDelegate (introduced in iOS 13), implement both scene delegate methods below.
- Swift
// For Custom URL Scheme returns, implement this scene delegate method:
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
URLContexts.forEach { context in
if context.url.scheme?.localizedCaseInsensitiveCompare("com.your-company.your-app.payments") == .orderedSame {
BTAppContextSwitcher.sharedInstance.handleOpenURL(context: context)
}
}
}
// For Universal Link returns, implement this scene delegate method:
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
if let url = userActivity.webpageURL, url.path.contains("braintree-payments") {
BTAppContextSwitcher.sharedInstance.handleOpen(url)
}
}Otherwise, if you aren't using UISceneDelegate, call handleOpenURL method from within the application:openURL:options app delegate method.
- Swift
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
if url.scheme?.localizedCaseInsensitiveCompare("com.your-company.your-app.payments") == .orderedSame {
return BTAppContextSwitcher.sharedInstance.handleOpen(url)
}
return false
}Location Permissions
The Braintree iOS SDK uses device and browser location data for fraud detection when available (i.e. when location permissions have already been requested by your app and granted by the user). While you do not need to request location data from users in order to use Braintree, Apple requires a NSLocationWhenInUseUsageDescription key in your Info.plist if your app contains code referencing location APIs. If your app does not request location data, you will still need to include a NSLocationWhenInUseUsageDescription plist entry.