The generated SDK depends on the AWS Mobile SDK for iOS. There are three ways to import it into your project:
- CocoaPods
- Frameworks
- Carthage
You should use one of these two ways to import the AWS Mobile SDK but not both. Importing both ways loads two copies of the SDK into the project and causes compiler errors.
-
The AWS Mobile SDK for iOS is available through CocoaPods. If you have not installed CocoaPods, install it by running the command:
$ gem install cocoapods $ pod setupDepending on your system settings, you may have to use
sudofor installingcocoapodsas follows:$ sudo gem install cocoapods $ pod setup -
Move the generated
Podfileto the same directory as your Xcode project file. Additionally starting from CocoaPods 1.0.0 you need to explicitly mention the target. To do this update the<YourXCodeTarget>section inPodfile. If your project already hasPodfile, you can add the following line to the existingPodfile.pod 'AWSAPIGateway', '~> 2.4.7' -
Then run the following command:
$ pod install -
Open up
*.xcworkspacewith Xcode. -
Add all files (
*.swiftand*.hfiles) under thegenerated-srcdirectory to your Xcode project. The generated-src already includes the Bridging header file (Bridging_Header.h), include that file in your build settings for xcode target. If you already have a bridging header then add#import "AWSApiGatewayBridge.h"
to your list of imports in the bridging header.
-
Download the SDK from http://aws.amazon.com/mobile/sdk. Amazon API Gateway is supported with the version 2.4.0 and later.
-
With your project open in Xcode, select your Target. Under General tab, find Embedded Binaries and then click the + button.
-
Click the Add Other... button, navigate to the
AWSCore.framework&AWSAPIGateway.frameworkfiles and select them. Check the Destination: Copy items if needed checkbox when prompted. -
Under the Buid Phases tab in your Target, click the + button on the top left and then select New Run Script Phase. Then setup the build phase as follows. Make sure this phase is below the
Embed Frameworksphase.Shell /bin/sh bash "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/AWSCore.framework/strip-frameworks.sh" Show environment variables in build log: Checked Run script only when installing: Not checked Input Files: Empty Output Files: Empty
-
Install the latest version of Carthage.
-
Add the following to your
Cartfile:github "aws/aws-sdk-ios" -
Then run the following command:
$ carthage update -
With your project open in Xcode, select your Target. Under General tab, find Embedded Binaries and then click the + button.
-
Click the Add Other... button, navigate to the
AWS<#ServiceName#>.frameworkfiles underCarthage>Build>iOSand select them. Do not check the Destination: Copy items if needed checkbox when prompted.* `AWSCore.framework` * `AWSAPIGateway.framework` -
Under the Buid Phases tab in your Target, click the + button on the top left and then select New Run Script Phase. Then setup the build phase as follows. Make sure this phase is below the
Embed Frameworksphase.Shell /bin/sh bash "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/AWSCore.framework/strip-frameworks.sh" Show environment variables in build log: Checked Run script only when installing: Not checked Input Files: Empty Output Files: Empty
-
Grab the
defaultClientfrom your codelet client = MYPREFIXWeatherAPIClient.defaultClient() -
You can now call your method using the client SDK
client.weatherGet(appid q(q).continueWithBlock{ (task: AWSTask?) -> AnyObject? in if let error = task.error { print("Error occurred: \(error)") return nil } if let result = task.result { // Do something with result } return nil }
#Using AWS IAM for authorization
To use AWS IAM to authorize API calls you can set an AWSCognitoCredentialsProvider object as the default provider for the SDK.
let credentialsProvider = AWSCognitoCredentialsProvider(regionType: CognitoRegionType, identityPoolId: CognitoIdentityPoolId)
let configuration = AWSServiceConfiguration(region: DefaultServiceRegionType, credentialsProvider: credentialsProvider)
AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration
#Using API Keys
You can set the apiKey property of the generated SDK to send API Keys in your requests.
client.APIKey = @"your api key";