Create a Login with Amazon Project
If you do not yet have an app project for using Login with Amazon, you should create one now. If you have an existing app, skip to Install the Login with Amazon Library below.
- Create a New Project in Xcode
- Install the Login with Amazon Library
- Add your API Key to your App Property List
- Add a URL Scheme to Your App Property List
Create a New Project in Xcode
- Launch Xcode.
- If you are presented with a Welcome to Xcode dialog, select Create a New Xcode Project. Otherwise, in the File menu, select New and Project.
- Select the type of project you wish to create and click Next.
- Enter a Product Name and a Company Identifier. Note your Bundle Identifier, and click Next.
- Select a location to store your project and click Create.
You will now have a new project that you can use to call Login with Amazon.
Install the Login with Amazon Library
If you have not yet downloaded the Login with Amazon SDK for iOS, see Install the Login with Amazon SDK for iOS.
A Login with Amazon project must link the LoginWithAmazon.framework
and Security.framework
libraries. You will also need to configure the framework search path to find the Login with Amazon headers.
- If your project doesn't have a Frameworks folder, right-click the project name in the Navigator pane in Xcode, then click New Group.
- Name the new group Frameworks.
- Select the Frameworks folder and click File from the Main menu.
- Select Add Files to Project.
- In the dialog, select
LoginWithAmazon.framework
and click Add. If you used the Login with Amazon 1.0 library, delete thelogin-with-amazon-sdk
directory andlogin-with-amazon-sdk.a
from the Frameworks. Click Edit from the main menu and select Delete. - Select the name of your project in the Project Navigator. The Project Editor will appear in the editor area of the Xcode workspace.
- Click your project name under Targets, and select Build Phases. Expand Link Binary with Libraries and click the plus sign to add a library.
- In the search box, type Security.framework. Select Security.framework and click Add.
-
In the search box, type SafariServices.framework. Select SafariServices.framework and click Add.
- Select Build Settings. Click All to view all settings.
-
Under Search Paths, ensure that the
LoginWithAmazon.framework
directory is in the Framework Search Paths. For example: - Before building your project, if you used the Login with Amazon 1.0 library, replace
#import "AIMobileLib.h"
,#import "AIAuthenticationDelegate.h"
, and#import "AIError.h"
in your source files with a single#import <LoginWithAmazon/LoginWithAmazon.h>
. TheLoginWithAmazon.h
line includes all the Login with Amazon headers at once. Additionally, you can remove any references to the 1.0 library path in the Header Search Paths or** Library Search Paths**. - From the Main menu, click Product and select Build. The build should complete successfully.
Add your API Key to your App Property List
When you register your iOS application with Login with Amazon, you are assigned an API key
. This is an identifier that the Amazon Mobile Library will use to identify your application to the Login with Amazon authorization service
. The Amazon Mobile Library loads this value at runtime from the APIKey
property value in your application's Information Property List.
-
With your project open, select the Supporting Files folder, then select the
<project>-Info.plist
file (where<project>
is the name of your project). This should open the property list for editing: - Make sure none of the entries are selected. Then, in the main menu, click Editor, and Add Item. Type APIKey and press Enter.
- Double-click under the Value column to add a value. Paste your API Key as the value.
Add a URL Scheme to Your App Property List
When the user logs in, they will be presented with an Amazon login page. In order for your app to receive confirmation of their login, you must add a URL scheme so the web page can redirect back to your app. The URL scheme must be declared as amzn-<bundleID>
(for example, amzn-com.example.app
). For more information, see Using URL Schemes to Communicate with Apps on developer.apple.com.
-
With your project open, select the Supporting Files folder, then select the
<project>-Info.plist
file (where<project>
is the name of your project). This should open the property list for editing: - Make sure none of the entries are selected. Then, in the main menu, click Editor, and Add Item. Type or select URL types and press Enter.
- Expand URL types to reveal Item 0. Select Item 0 and, from the main menu, click Editor and Add Item. Type or select URL Identifier and press Enter.
- Select Item 0 under URL Identifier and double-click under the Value column to add a value. The value is your bundle ID. You can find your bundle ID listed as Bundle identifier in the property list.
- Select Item 0 under URL types and, from the main menu, click Editor and Add Item. Type or select URL Schemes and press Enter.
- Select Item 0 under URL Schemes and double-click under the Value column to add a value. The value is your bundle ID with
amzn-
prepended (for example, amzn-com.example.app). You can find your bundle ID listed as Bundle identifier in the property list.