NHNCloudIAPKit iOS SDK
- NHNCloudIAPKit is an iOS SDK that provides StoreKit2 support for in-app purchases.
- It is designed to be used with Swift and includes a sample application to demonstrate its functionality.
- Swift 5.9.2 or later
- Xcode 15.1 or later
- iOS 15.0 or later
platform :ios, '15.0'
use_frameworks!
target '{YOUR PROJECT TARGET NAME}' do
pod 'NHNCloudIAPKit'
endhttps://github.com/nhn/nhncloud.iap.ios.sdk
- Frameworks, Libraries, and Embedded Content add StoreKit.framework
- Download the latest release from the releases page.
- Unzip the downloaded file.
- Drag and drop the
NHNCloudIAPKit.xcframeworkinto your Xcode project. - Ensure that the
NHNCloudIAPKit.xcframeworkis added to your target's "Frameworks, Libraries, and Embedded Content" section. - Change Embed value is Do Not Embed the framework.
- Add the
StoreKit.frameworkto your target's "Frameworks, Libraries, and Embedded Content" section.
- In your Xcode project, navigate to the "Signing & Capabilities" tab.
- Click on the "+" button to add a new capability.
- Select "In-App Purchase" from the list of capabilities.
- import NHNCloudIAPKit
import NHNCloudIAPKit- initialize NHNCloudIAPKit and delegate
extension YourViewController: InAppPurchaseProtocol {
func initializeIAPKit() {
NHNCloudInAppPurchase.setUserId(currentUserId)
let configuration = Configuration(appKey: "your_app_key")
NHNCloudInAppPurchase.initialize(configuration: configuration)
NHNCloudInAppPurchase.setDelegate(self)
}
func shouldProceedWithStorePurchaseForProduct(_ product: InAppPurchaseProduct) -> Bool {
return true
}
public func didReceivePurchaseResult(_ purchaseResult: InAppPurchaseResult?,
_ error: InAppPurchaseError?) {
if error != nil {
print("Purchase failed: \(String(describing: error?.localizedDescription))")
}
if let result = purchaseResult {
print("Purchase successful: \(result)")
}
}
}- request products
func requestProducts() {
Task {
do {
let productResponse = try await NHNCloudInAppPurchase.requestProducts()
products = productResponse.products
invalidProducts = productResponse.invalidProducts
} catch {
print("Error: \(error)")
}
}
}- purchase product
func purchaseProduct(_ product: InAppPurchaseProduct) {
Task {
do {
let purchaseResult = try await NHNCloudInAppPurchase.purchase(product: product,
payload: "{\"key\":\"value\"}")
} catch {
print("Error: \(error)")
}
}
}- unconsume purchase result
func unconsumablePurchaseResult() {
Task {
do {
let purchaseResults = try await NHNCloudInAppPurchase.requestConsumablePurchases()
} catch {
print("Error: \(error)")
}
}
}