zoukankan      html  css  js  c++  java
  • StoreKit

     

    import UIKit

    import StoreKit

     

    class ViewController: UITableViewController {

     

        var products: [SKProduct] = [SKProduct]() {

            

            didSet {

                tableView.reloadData()

            }

            

        }

        

        

        override func viewDidLoad() {

            super.viewDidLoad()

            

            // 1. 从我们自己的服务器, 获取需要销售的额商品

            

            LZJDataTool.getGoodsList { (ids: Set<String>) -> () in

                // 2. 拿到需要销售的额商品, 到苹果服务器, 进行验证, 看下, 哪些商品, 才可以真正被销售

                // 2.1 创建一个商品请求, 请求哪些商品可以真正的呗销售

                let request: SKProductsRequest = SKProductsRequest(productIdentifiers: ids)

                

                // 2.1.1 设置代理, 接收可以被销售的商品列表数据

                request.delegate = self

                

                // 2.2 发送请求

                request.start()

     

            }

         

        }

     

     

    }

     

     

    extension ViewController {

        

        override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

            return products.count

        }

        

        override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

            

            let cell = tableView.dequeueReusableCellWithIdentifier("product")

            

            

            // 获取对应的商品数据模型, 进行赋值

            let product = products[indexPath.row]

            // SKProduct

            cell?.textLabel?.text = product.localizedTitle

            cell?.detailTextLabel?.text = product.localizedDescription + "(product.price)"

            

            

            return cell!

        }

        

        

    }

     

     

    extension ViewController: SKProductsRequestDelegate {

        // 当请求完毕之后, 从苹果服务器获取到数据之后调用

        func productsRequest(request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) {

            

            // response 

            // products: 可以被销售的额商品

            // invalidProductIdentifiers: 无效的商品ID

            

            

            

            print(response.products)

            

            products = response.products

            

            print(response.invalidProductIdentifiers)

            

        }

    }

     

     

     

    ----------------------------------

    //  获取需要销售的商品

    import Foundation

     

    class LZJDataTool: NSObject {

     

        

        class func getGoodsList(result: (Set<String>)->()) {

            

            // 先我们自己的服务器发送网络请求, 获取商品数据

            

            

            result(["com.shiyi.zidan", "com.shiyi.jiguanqiang", "com.shiyi.jiguanqiang2", "com.shiyi.jiguanqiang3"])

            

            

        }

        

    }

  • 相关阅读:
    hdu 4614 线段树 二分
    cf 1066d 思维 二分
    lca 最大生成树 逆向思维 2018 徐州赛区网络预赛j
    rmq学习
    hdu 5692 dfs序 线段树
    dfs序介绍
    poj 3321 dfs序 树状数组 前向星
    cf 1060d 思维贪心
    【PAT甲级】1126 Eulerian Path (25分)
    【PAT甲级】1125 Chain the Ropes (25分)
  • 原文地址:https://www.cnblogs.com/liuzhenjie/p/5417334.html
Copyright © 2011-2022 走看看