Set Up the Amazon Pay SDK
Follow these steps to set up the Amazon Pay SDK.
-
Download the specific SDK version available at Amazon Pay SDKs.
Caution
If you use a version of the Amazon Pay SDK not downloaded from the above link, your integration may fail.
-
Add the
AmazonPayHardenediOSSDK.framework
andLoginWithAmazon.framework
files into your project by following the steps here. -
Generate and validate your API keys. For more information, see Obtain API Keys.
-
Update
info.plist
. Append the following snippet to theinfo.plist
file by accessing it as a source code:<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLSchemes</key> <array> <string>amzn-$(PRODUCT_BUNDLE_IDENTIFIER)</string> </array> <key>CFBundleURLName</key> <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> </dict> </array>
This ensures proper handling of URL schemes within your application.
-
Generate a code challenge based on the iOS environment you are using:
-
Code challenge for Objective C
-
Code challenge for Swift
-
-
Configure
AppDelegate.m
(Objective-C) orAppDelegate.swift
(Swift):#import <LoginWithAmazon/LoginWithAmazon.h> #import <AmazonPayHardenediOSSDK/AmazonPay.h> static NSString *AMZN_REGEX = @"amzn.*"; - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:AMZN_REGEX options:0 error:nil]; if ([regex numberOfMatchesInString:[url absoluteString] options:0 range:NSMakeRange(0, [[url absoluteString] length])] > 0) { return [[AmazonPay sharedInstance] handleRedirectURL:url sourceApplication:sourceApplication]; } return false; } - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options { NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:AMZN_REGEX options:0 error:nil]; if ([regex numberOfMatchesInString:[url absoluteString] options:0 range:NSMakeRange(0, [[url absoluteString] length])] > 0) { return [[AmazonPay sharedInstance] handleRedirectURL:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]]; } return false; }
import UIKit import AmazonPayHardenediOSSDK @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool { do { let regex = try NSRegularExpression(pattern: "amzn-.*") let results = regex.matches(in: url.absoluteString, range: NSRange(url.absoluteString.startIndex..., in: url.absoluteString)) if results.count > 0 { return AmazonPay.sharedInstance().handleRedirectURL(url, sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as! String) } else { return false } } catch let error { print("invalid regex: \\(error.localizedDescription)") return false } } }