티스토리 뷰
안녕하세요, 은조공주🥰입니다.
3편에서 설명할 내용은 아주 짧고 적기 때문에, 2편에 이어 바로 포스팅을 하도록 하겠습니다.
( 2021-03-16 기준 Apple document 업데이트 내용 반영되었습니다.)
[ 1.SKStorefront ]
Apple AppStore storefront 의 위치 및 고유 식별자를 포함하는 객체
class SKStorefront : NSObject
SKStorefront 는 매장(storefront) 정보를 SKPaymentQueue 의 읽기 전용 속성으로 표시합니다. 그리고, (앱에서 제공할...?) 상품 ID 리스트와 storefront 리스트를 앱 내에서 가지고 있어야 합니다.
(이 매장 - Storefront 라는 것에 대해 고민해봤는데, ... (왜냐면 정확히 어떤건지 느낌이 잘 안왔어요ㅠ.ㅠ) 한국 앱스토어 / 미국 앱스토어 / 독일 앱스토어 등 정말 앱스토어의 각 국가별 지점? 정보를 나타내는 것 같습니다.)
App Store Connect 를 통해 생성한 IAP 상품은 AppStore 와 함께 모든 지역에서 판매될 수 있습니다.
매장 정보를 사용하여 유저의 지역을 판단하고, 해당 지역에 적합한 IAP 상품을 제공할 수 있습니다. 이를 위해서는 상품ID 목록을 유지하고 있어야 합니다.
(Storefront 정보를 유저 정보와 함께 저장하지 말아야한다. 언제든지 바뀔 수 있다. 앱에서 유저에게 상품 정보나 가용성을 표시하기 직전에 storefront 식별자를 가져와야 한다. Storefront 는 유저 프로필을 향상..? 시키거나, 광고 또는 마케팅 목적으로 유저 정보를 추적하는 데에 사용되지 말아야 한다.)
Show Products Based on the Current Storefront
다음의 예시 메소드 (shouldShow) 는 만약 상품이 해당 storefront에 적절하지 않으면 false를 리턴합니다.
// 상품을 노출할지 말지를 정하기 위해 storefront값을 사용
func shouldShow(_ productIdentifier: String, in storefront: SKStorefront) -> Bool {
var shouldShow = true
// myProducts is a dictionary representing your own metadata for products,
// keyed on an SKProduct.productIdentifier.
if let myProduct = myProducts[productIdentifier] {
shouldShow = myProduct.countryCodes.contains(storefront.countryCode)
}
return shouldShow
}
func fetchProductInfo() {
var identifiers = Set<String>()
if let storefront = SKPaymentQueue.default().storefront {
for (identifier, _) in myProducts {
if shouldShow(identifier, in: storefront) {
identifiers.insert(identifier)
}
}
let request = SKProductsRequest(productIdentifiers: identifiers)
request.delegate = self
request.start()
}
}
Listen for Storefront Changes
Storefront값은 언제든지 바뀔 수 있습니다. 이 값의 변화에 대응하기 위해, paymentQueueDidChangeStorefront(_:) <- 요 메소드를 구현해야 합니다.
func paymentQueueDidChangeStorefront(_ queue: SKPaymentQueue) {
if let storefront = queue.storefront {
// Refresh the displayed products based on the new storefront.
for product in storeProducts {
if shouldShow(product.productIdentifier, in: storefront) {
// Display this product in your store UI.
}
}
}
}
Respond to Storefront Changes
"현재 Storefront" 는 언제든지 바뀔 수 있고, 심지어 transaction 진행 중에도 바뀔 수 있습니다! 그러면, 트랜잭션 도중에 storefront가 바뀌었을 경우 이 트랜잭션을 계속 할지 말지에 대해서도 결정해줄 필요가 있습니다. 이는 다음과 같이 구현합니다. (메소드 참조 - paymentQueue(_:shouldContinue:in:))
SKPaymentQueue.default().delegate = self // Set your object as the SKPaymentQueue delegate.
func paymentQueue(_ paymentQueue: SKPaymentQueue,
shouldContinue transaction: SKPaymentTransaction,
in newStorefront: SKStorefront) -> Bool {
return shouldShow(transaction.payment.productIdentifier, in: newStorefront)
}
만약 업데이트된 storefront에서 해당 상품이 더이상 available하지 않다면, transation은 SKError.Code.storeProductNotAvailable <- 요런 에러와 함께 실패합니다. 요 에러는 paymentQueue(_:updatedTransactions:) 요 메소드에서 핸들링해주어 유저에게 왜 transaction을 마무리할 수 없었는지 UI상으로 알려줄 수 있도록 합시다 ㅎㅎ
func paymentQueue(_ queue: SKPaymentQueue,
updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions {
if let transactionError = transaction.error as NSError?,
transactionError.domain == SKErrorDomain
&& transactionError.code == SKError.storeProductNotAvailable.rawValue {
// Show an alert.
}
}
}
Identifying the Storefront
var countryCode: String // 앱스토어 storefront 와 연관된 세자리의 국가코드
var identifier: String // 앱스토어 storefront 의 고유 ID (Apple 에 의해 정해진)
[ 참조 문서 ]
https://developer.apple.com/documentation/storekit/skstorefront
'iOS > IAP' 카테고리의 다른 글
[ IAP ] 5. Purchase Validation (7) | 2019.12.16 |
---|---|
[ IAP ] 4. Purchases (3) | 2019.12.12 |
[ IAP ] 2. Product Information (1) | 2019.12.12 |
[ IAP ] 1. Essentials (2) | 2019.12.11 |
[ IAP ] Overview (0) | 2019.11.12 |
- Total
- Today
- Yesterday
- ios iap
- Concurrency
- ios 인앱결제
- Apple
- InAppPurchase
- 일상
- I'm_in_Bamberg
- async/await
- IAP
- MacOS
- 인앱결제
- ios
- Swift
- storekit
- FinderSync
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 26 | 27 | 28 |