The Braintree iOS SDK helps you accept payments in your iOS app.
Requirements
- Xcode 10+ and iOS 9.0+ Base SDK
- iOS 8.0+ deployment target
Installation
There are multiple ways to include Braintree in your project. See the Installation
section of our README.
Setup for app switch
To handle payments that involve switching to another app or SFSafariViewController
for authentication, you must register a URL type and configure your app to return from app switches.
Register a URL type
- In Xcode, click on your project in the Project Navigator and navigate to App Target > Info > URL Types
- Click [+] to add a new URL type
- Under URL Schemes, enter your app switch return URL scheme. This scheme must start with your app's Bundle ID and be dedicated to Braintree app switch returns. For example, if the app bundle ID is
com.your-company.Your-App
, then your URL scheme could becom.your-company.Your-App.payments
.
Testing the URL type
You can test out your new URL scheme by opening up a URL that starts with it (e.g. com.your-company.Your-App.payments://test
) in Mobile Safari on your iOS Device or Simulator.
In addition, always test your app switching on a real device.
Update your application delegate
In your AppDelegate's application:didFinishLaunchingWithOptions:
implementation, use setReturnURLScheme:
with the value you set above.
For example:
#import "AppDelegate.h"
#import "BraintreeCore.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[BTAppSwitch setReturnURLScheme:@"com.your-company.Your-App.payments"];
return YES;
}
Then in your application delegate, pass the payment authorization URL to Braintree for finalization:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
if ([url.scheme localizedCaseInsensitiveCompare:@"com.your-company.Your-App.payments"] == NSOrderedSame) {
return [BTAppSwitch handleOpenURL:url options:options];
}
return NO;
}
// If you support iOS 8, add the following method.
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
if ([url.scheme localizedCaseInsensitiveCompare:@"com.your-company.Your-App.payments"] == NSOrderedSame) {
return [BTAppSwitch handleOpenURL:url sourceApplication:sourceApplication];
}
return NO;
}
Supporting iOS 9
iOS 9 introduces new security restrictions that can impact the behavior of the Braintree SDK.
App Transport Security
As of 09/30/2015, all endpoints contacted by the Braintree iOS SDK are compatible with Apple's App Transport Security requirements. No ATS exceptions are necessary.
If your app's Info.plist
previously contained NSExceptionDomains
entries for api.braintreegateway.com
or kaptcha.com
(for apps using Kount), we recommend you remove these exceptions. As with any changes which may affect your app in production, please be sure to test and verify all behavior before releasing an update to the App Store.
See also
- Get Started
- Braintree iOS SDK reference
- Braintree iOS GitHub repository
- Braintree iOS version changelog