iOS 모바일 인증 SDK
이러한 유틸리티는 iOS 애플리케이션에서 Amazon Location Service API 직접 호출을 할 때 인증하는 데 도움이 됩니다. 이는 특히 Amazon Cognito 또는 API 키를 인증 방법으로 사용할 때 도움이 됩니다.
iOS 모바일 인증 SDK는 github: iOS용 Amazon Location Service 모바일 인증 SDK
설치
Xcode 프로젝트에 SDK를 설치합니다.
파일로 이동한 다음 XCode 프로젝트에서 패키지 종속성 추가를 선택합니다.
패키지 URL: https://github.com/aws-geospatial/amazon-location-mobile-auth-sdk-ios/
를 검색 창에 입력하고 Enter 키를 누릅니다. amazon-location-mobile-auth-sdk-ios
패키지를 선택하고 패키지 추가를 누릅니다.AmazonLocationiOSAuthSDK
패키지 제품을 선택하고 패키지 추가를 누릅니다.
인증 함수
인증 헬퍼 SDK에는 다음과 같은 함수가 있습니다.
authHelper.authenticateWithApiKey("My-Amazon-Location-API-Key"): LocationCredentialsProvider
: 이 함수는 API 키로 작동하도록 초기화된LocationCredentialsProvider
를 반환합니다.authHelper.authenticateWithCognitoIdentityPool("My-Cognito-Identity-Pool-Id"): LocationCredentialsProvider
: 이 함수는 Amazon Cognito ID 풀에서 작동하도록 초기화된LocationCredentialsProvider
를 반환합니다.
사용량
모바일 인증 SDK를 사용하려면 활동에 다음 문을 추가합니다.
import AmazonLocationiOSAuthSDK import AWSLocationXCF
인증 헬퍼 및 위치 클라이언트 공급자 인스턴스를 생성할 때 두 가지 옵션이 있습니다. Amazon Location API 키 또는 Amazon Cognito를 사용하여 인스턴스를 생성할 수 있습니다.
-
Amazon Location API 키를 사용하여 인증 헬퍼 인스턴스를 생성하려면 다음과 같이 헬퍼 클래스를 선언합니다.
let authHelper = AuthHelper() let locationCredentialsProvider = authHelper.authenticateWithAPIKey(apiKey: "
My-Amazon-Location-API-Key
", region: "account-region
") -
Amazon Cognito를 사용하여 인증 헬퍼 인스턴스를 생성하려면 다음과 같이 헬퍼 클래스를 선언합니다.
let authHelper = AuthHelper() let locationCredentialsProvider = authHelper.authenticateWithCognitoUserPool(identityPoolId: "
My-Amazon-Location-API-Key
", region: "account-region
")
위치 자격 증명 공급자를 사용하여 Amazon Location 클라이언트 인스턴스를 생성하고 Amazon Location 서비스에 직접적으로 호출할 수 있습니다. 다음 예제에서는 지정된 위도 및 경도에 가까운 장소를 검색합니다.
let locationClient = AWSLocation.default() let searchPlaceIndexForPositionRequest = AWSLocationSearchPlaceIndexForPositionRequest()! searchPlaceIndexForPositionRequest.indexName = "My-Place-Index-Name" searchPlaceIndexForPositionRequest.position = [30.405423, -97.718833] let nearbyPlaces = locationClient.searchPlaceIndex(forPosition: searchPlaceIndexForPositionRequest)