YMTInAppPurchase 1.1

YMTInAppPurchase 1.1

维护者 MasamiYamate.



  • MasamiYamate

YMTInAppPurchaseFramework

此框架使运行内购流程变得容易。

描述

在购买应用程序的过程中需要花费时间和精力,如收据验证。使用此框架,我们可以轻松处理此类内购项目处理。

安装

只需将YMTVersionAlert.framework文件夹添加到您的项目中
或使用Podfile与CocoaPods

pod 'YMTInAppPurchase'

运行

pod install

使用

启动验证服务器

iap-node-api

此框架基于与 iap-node-api 一起使用的假设。需要启动 iap-node-api ,以便从外部访问。

导入

import YMTInAppPurchase

步骤1:必须的密钥设置

在 AppDelegate.swift 的 didFinishLaunchingWithOptions 中,设置收据验证 URL 和内购共享密钥。

//
//  AppDelegate.swift
//  YMTInAppPurchaseSampleApp
//

import UIKit

// Framework import
import YMTInAppPurchase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        
        // Set In-App Purchase Shared Secret Key
        YMTInAppPurchase.shared.setAppShareKey("In-App Purchase Shared Secret Key")
        
        // Set registration setting and restoration confirmation API end point
        let registration = "registration url"
        let restore = "restore url"
        YMTInAppPurchase.shared.setValidationUrls(regist: registration, restore: restore)

        return true
    }

    func applicationWillResignActive(_ application: UIApplication) {}

    func applicationDidEnterBackground(_ application: UIApplication) {}

    func applicationWillEnterForeground(_ application: UIApplication) {}

    func applicationDidBecomeActive(_ application: UIApplication) {}

    func applicationWillTerminate(_ application: UIApplication) {}

}

步骤2:确认在 App Store 中销售的物品

将应用程序中销售的物品 ID 传递以确定它是否是有效产品。请在显示物品销售页面之前执行。

let productIds = ["productId" , "productId"]
YMTInAppPurchase.shared.setProductIdss(productIds, callback: {
	// Such view refresh event etc.
}

步骤3:执行交易

它获取用户指定的项目的 SKProduct 并将其传递给以下方法。如果在购买过程结束后执行并成功,则将销售物品的 ID 返回为字符串。

YMTInAppPurchase.shared.startTransaction(product, callback: { productId in
    //ProductId is returned.
    //Perform function release etc. based on product ID.
    if productId != nil {
        //Perform function release etc.
    }
})

恢复请求

如果用户更换了新 iPhone 并重新安装了应用程序,则需要恢复购买的项目。这很容易恢复。只需执行以下方法即可获取要恢复的项目的 ID。

YMTInAppPurchase.shared.startRestore(callback: { restoreProductIds in
    //The product ID to be restored is returned.
    //Perform processing such as cancellation of functions based on the product ID
})

许可

MIT