결제를 사용 설정하고 API 키를 만든 후에는 앱 개발에 사용할 Xcode 프로젝트를 설정할 수 있습니다.
각 출시 버전에서 출시 노트를 확인할 수 있습니다.
1단계: 필수 소프트웨어 설치하기
iOS용 Places SDK를 사용하여 프로젝트를 빌드하려면 다음이 필요합니다.
- Xcode 버전 14.0 이상
- Cocoapods
- 아직 Xcode 프로젝트가 없으면 지금 만들어 로컬 시스템에 저장합니다. iOS 개발을 처음 사용하는 경우 새 프로젝트를 만들고 iOS App template을 선택합니다.
- 프로젝트 디렉터리에
Podfile
파일을 만듭니다. 이 파일은 프로젝트의 종속 항목을 정의합니다. Podfile
를 수정하고 버전과 함께 종속 항목을 추가합니다. 다음은 애플리케이션 대상 이름과GooglePlaces
포드의 이름을 지정하는 예시입니다.source 'https://github.com/CocoaPods/Specs.git' platform :ios, '14.0' target 'YOUR_APPLICATION_TARGET_NAME_HERE' do pod 'GooglePlaces', '8.2.1' end
항상 최신 버전을 사용할 수 있도록 최신 버전이 있는지 감지하도록pod outdated
를 정기적으로 실행해야 합니다.Podfile
을 저장합니다.터미널을 열고
Podfile
이 포함된 디렉터리로 이동합니다.cd <path-to-project>
pod install
명령어를 실행합니다.Podfile
에 지정된 API가 API에 포함된 종속 항목과 함께 설치됩니다.pod install
Xcode를 닫은 다음 프로젝트의
.xcworkspace
파일을 (더블클릭하여) 열어 Xcode를 실행합니다. 이 때부터는.xcworkspace
파일을 사용하여 프로젝트를 열어야 합니다.- 터미널을 열고
Podfile
가 포함된 프로젝트 디렉터리로 이동합니다. pod update
명령어를 실행합니다. 이렇게 하면Podfile
에 지정된 모든 API가 최신 버전으로 업데이트됩니다.- SDK 소스 파일 GooglePlaces-8.2.1을 다운로드합니다.
- 소스 파일을 압축해제합니다. Frameworks 폴더로 이동하여 XCFramework에 액세스합니다.
- Xcode를 실행하고 기존 프로젝트를 열거나 새 프로젝트를 만듭니다. iOS를 처음 사용하는 경우 새 프로젝트를 만들고 iOS 앱 템플릿을 선택합니다.
- 다음 XCFramework를 프레임워크, 라이브러리 및 삽입된 콘텐츠의 프로젝트로 드래그합니다. 삽입 안함을 선택해야 합니다.
GooglePlaces-x.x.x/GooglePlaces.xcframework
- 프로젝트에서
GooglePlaces.xcframework
를 마우스 오른쪽 버튼으로 클릭하고 Show In Finder를 선택합니다. ios-arm64/GooglePlaces.framework/Resources
폴더에서 Xcode 프로젝트의 최상위 디렉터리로GooglePlaces.bundle
를 드래그합니다. 메시지가 표시되면 Copy items into destination group's folder(항목을 대상 그룹 폴더에 복사)가 선택되지 않았는지 확인합니다.- 프로젝트 탐색기에서 프로젝트를 선택하고 애플리케이션의 대상을 선택합니다.
- 빌드 단계 탭을 열고 바이너리를 라이브러리와 연결 내에서 다음 프레임워크와 라이브러리를 추가합니다.
CoreGraphics.framework
CoreLocation.framework
libc++.tbd
libz.tbd
QuartzCore.framework
UIKit.framework
특정 대상 대신 자신의 프로젝트를 선택하고 Build Settings(빌드 설정) 탭을 엽니다.
- Other Linker Flags(기타 링커 플래그) 섹션에서
-ObjC
를 추가합니다. 이러한 설정이 표시되지 않으면 Build Settings(빌드 설정) 표시줄의 필터를 Basic(기본)에서 All(모두)로 변경합니다. - SDK 소스 파일 다운로드: GooglePlaces-8.2.1
- 소스 파일을 압축해제합니다.
- Xcode를 실행하고 기존 프로젝트를 열거나 새 프로젝트를 만듭니다. iOS 개발을 처음 사용하는 경우 새 프로젝트를 만들고 iOS App template을 선택합니다.
- 프로젝트의 이전 릴리스에서 모든 Maps 번들을 삭제합니다.
- 다음 번들을 프로젝트로 드래그합니다 (메시지가 표시되면 필요한 경우 항목 복사 선택).
GooglePlaces-x.x.x/Frameworks/GooglePlaces.xcframework
- 프로젝트에서
GooglePlaces.xcframework
를 마우스 오른쪽 버튼으로 클릭하고 Show In Finder(Finder에서 보기)를 선택합니다. Resources
폴더에서GooglePlaces.bundle
를 프로젝트로 드래그합니다. 메시지가 표시되면 Copy items into destination group's folder(항목을 대상 그룹의 폴더에 복사)가 선택되지 않았는지 확인합니다.- Project Navigator에서 프로젝트를 선택하고 애플리케이션의 대상을 선택합니다.
- 빌드 단계 탭을 열고 바이너리를 라이브러리와 연결 내에 다음 프레임워크와 라이브러리를 추가합니다.
CoreGraphics.framework
CoreLocation.framework
libc++.tbd
libz.tbd
QuartzCore.framework
UIKit.framework
특정 대상 대신 자신의 프로젝트를 선택하고 Build Settings(빌드 설정) 탭을 엽니다.
- Other Linker Flags(기타 링커 플래그) 섹션에서
-ObjC
를 추가합니다. 이러한 설정이 표시되지 않으면 Build Settings(빌드 설정) 표시줄의 필터를 Basic(기본)에서 All(모두)로 변경합니다. - 다음 import 문을 추가합니다.
import GooglePlaces
application(_:didFinishLaunchingWithOptions:)
메서드에 다음을 추가하여 YOUR_API_KEY를GMSPlacesClient.provideAPIKey("YOUR_API_KEY")
로 바꿉니다.- 다음 import 문을 추가합니다.
@import GooglePlaces;
application:didFinishLaunchingWithOptions:
메서드에 다음을 추가하여 YOUR_API_KEY를[GMSPlacesClient provideAPIKey:@"YOUR_API_KEY"];
로 바꿉니다.
2단계: Xcode 프로젝트 만들기 및 iOS용 Places SDK 설치
새 프로젝트에 API를 설치하려면 다음 단계를 따르세요.CocoaPods 사용
iOS용 Places SDK는 모든 장소 기능이 포함된 CocoaPod 포드인 GooglePlaces로 제공됩니다.
CocoaPods는 Swift 및 Objective-C Cocoa 프로젝트용 오픈소스 종속 항목 관리자입니다. CocoaPods 도구가 아직 없다면 터미널에서 다음 명령어를 실행하여 macOS에 CocoaPods 도구를 설치합니다. 자세한 내용은 CocoaPods 시작 가이드를 참고하세요.
sudo gem install cocoapods
iOS용 Places SDK의 Podfile
를 만들고 이를 사용하여 SDK 및 종속 항목을 설치합니다.
기존 프로젝트의 API를 업데이트하려면 다음 단계를 따르세요.
XCFramework 설치
XCFramework는 M1 칩셋을 사용하는 머신을 비롯한 여러 플랫폼에서 사용하여 iOS용 Places SDK를 설치할 수 있는 바이너리 패키지입니다. 이 가이드에서는 iOS용 Places SDK가 포함된 XCFramework를 프로젝트에 추가하고 Xcode에서 빌드 설정을 구성하는 방법을 설명합니다.
수동
이 가이드에서는 프로젝트에 iOS용 Maps SDK를 수동으로 추가하고 Xcode에서 빌드 설정을 구성하는 방법을 설명합니다.
카타지 포함
수동 설치
이 가이드에서는 GooglePlaces 프레임워크를 프로젝트에 수동으로 추가하고 Xcode에서 빌드 설정을 구성하는 방법을 설명합니다.
3단계: 앱에 API 키 추가
다음 예에서 YOUR_API_KEY
를 이 API 키로 바꾸세요.
Swift
다음과 같이 API 키를 AppDelegate.swift
에 추가합니다.
Objective-C
다음과 같이 API 키를 AppDelegate.m
에 추가합니다.
4단계: 코드 작성 시작하기
다음 코드 샘플은 현재 장소를 가져오는 방법을 보여줍니다.
Swift
import GooglePlaces import UIKit class GetStartedViewController : UIViewController { // Add a pair of UILabels in Interface Builder, and connect the outlets to these variables. @IBOutlet private var nameLabel: UILabel! @IBOutlet private var addressLabel: UILabel! private var placesClient: GMSPlacesClient! override func viewDidLoad() { super.viewDidLoad() placesClient = GMSPlacesClient.shared() } // Add a UIButton in Interface Builder, and connect the action to this function. @IBAction func getCurrentPlace(_ sender: UIButton) { let placeFields: GMSPlaceField = [.name, .formattedAddress] placesClient.findPlaceLikelihoodsFromCurrentLocation(withPlaceFields: placeFields) { [weak self] (placeLikelihoods, error) in guard let strongSelf = self else { return } guard error == nil else { print("Current place error: \(error?.localizedDescription ?? "")") return } guard let place = placeLikelihoods?.first?.place else { strongSelf.nameLabel.text = "No current place" strongSelf.addressLabel.text = "" return } strongSelf.nameLabel.text = place.name strongSelf.addressLabel.text = place.formattedAddress } } }
Objective-C
#import "GetStartedViewController.h" @import GooglePlaces; @interface GetStartedViewController () // Add a pair of UILabels in Interface Builder and connect the outlets to these variables @property (weak, nonatomic) IBOutlet UILabel *nameLabel; @property (weak, nonatomic) IBOutlet UILabel *addressLabel; @end @implementation GetStartedViewController { GMSPlacesClient *_placesClient; } - (void)viewDidLoad { [super viewDidLoad]; _placesClient = [GMSPlacesClient sharedClient]; } // Add a pair of UILabels in Interface Builder and connect the outlets to these variables. - (IBAction)getCurrentPlace:(UIButton *)sender { GMSPlaceField placeFields = (GMSPlaceFieldName | GMSPlaceFieldFormattedAddress); __weak typeof(self) weakSelf = self; [_placesClient findPlaceLikelihoodsFromCurrentLocationWithPlaceFields:placeFields callback:^(NSArray<GMSPlaceLikelihood *> * _Nullable likelihoods, NSError * _Nullable error) { __typeof__(self) strongSelf = weakSelf; if (strongSelf == nil) { return; } if (error != nil) { NSLog(@"An error occurred %@", [error localizedDescription]); return; } GMSPlace *place = likelihoods.firstObject.place; if (place == nil) { strongSelf.nameLabel.text = @"No current place"; strongSelf.addressLabel.text = @""; return; } strongSelf.nameLabel.text = place.name; strongSelf.addressLabel.text = place.formattedAddress; }]; } @end
다음 단계
프로젝트가 구성되면 샘플 앱을 살펴볼 수 있습니다. CocoaPods v1.6.1이 설치되어 있어야 합니다.