Swift(스위프트): 앱 내부에서 팝업으로 앱 스토어 앱 정보 띄우기
Swift(스위프트): 앱 내부에서 팝업으로 앱 스토어 앱 정보 띄우기
Swift(스위프트): 앱 내부에서 팝업으로 앱 스토어 앱 띄우기
아래 움짤과 같이 자신이 만든 앱 내부에서(외부 브라우저나 앱스토어로 이동하지 않고) 다른 앱을 표시하고자 할 때 StoreKit을 사용합니다. 다른 앱을 홍보할 때 사용하면 좋습니다.
참고로 이번 예제는 시뮬레이터는 실행이 불가능하므로 실제 기기에서 테스트해야 합니다.
1: 위 작업을 실행하고자 하는 뷰 컨트롤러에서 StoreKit을 import 합니다.
1
2
import UIKit
import StoreKit
2: 아래 extension 을 추가합니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
extension ExampleViewController: SKStoreProductViewControllerDelegate {
func popupAppStore(identifier: Any) {
let parametersDictionary = [SKStoreProductParameterITunesItemIdentifier: identifier]
let store = SKStoreProductViewController()
store.delegate = self
/*
Attempt to load the selected product from the App Store. Display the store product view controller if success and print an error message,
otherwise.
*/
store.loadProduct(withParameters: parametersDictionary) { [unowned self] (result: Bool, error: Error?) in
if result {
self.present(store, animated: true, completion: {
print("The store view controller was presented.")
})
} else {
if let error = error {
// 에러 발생 또는 시뮬레이터의 경우 여기에 해야할 작업 작성
print("Error: \(error)")
}
}
}
}
}
identifier는 앱 스토어 아이디로(밑에 찾는 방법 설명)String또는Int형태로 입력합니다.- 예를 들어
"1631310626"또는1631310626로 입력할 수 있습니다.
- 예를 들어
3: 버튼 클릭, 또는 테이블 셀 클릭 등 이벤트 실행 영역에 아래와 같이 작성합니다.
1
2
3
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
popupAppStore(identifier: 앱스토어아이디)
}
참고로 identifier에 입력할 앱스토어 아이디 찾는 방법은 다음과 같습니다.
1) 앱 스토어 커넥트의 앱 정보 메뉴에서 보기
2) 앱 스토어의 URL에서 ‘id’ 를 제외한 나머지 숫자
This post is licensed under
CC BY 4.0
by the author.


