コード例 #1
0
        public override void HandleNotification(INotification notification)
        {
            var msgName = notification.name;

            switch (msgName)
            {
            case IAP_MSG.PURCHASE_SUCCESS:
                //////////////////////////////////////////////////////////////
                //// 应用内事件:记录购买的产品 ///////////////////////////////////
                //////////////////////////////////////////////////////////////
                // 只要购买成功, NonComsumable 类型的产品的购买信息,会被 komal 框架记录下来。可以通过
                // SDKManager.Instance.IsPurchased("remove_ads"); 这样的接口获取状态;
                IAPSuccessResult result = (IAPSuccessResult)notification.body;
                var product             = result.product;     // Unity IAP 返回的产品数据结构;
                var productKey          = result.productKey;  // 配置 IDConfig.cs 中用于程序购买的关键字(remove_ads)
                var productItem         = result.productItem; // 配置 IDConfig.cs 中,在 app store 上填写的信息;
                // 不是恢复购买的情况下
                if (!result.isRestore)
                {
                    // 向 AppsFlyer 发送消息
                    this.SendPurchaseEvent(productItem.ID,
                                           productItem.Type,
                                           productItem.Price.ToString(),
                                           productItem.Currency);
                }
                break;

            case MSG_GAMECENTER.GAMECENTER_LOGIN_SUCCESS:
                //////////////////////////////////////////////////////////////
                //// 应用内事件:记录登陆成功事件 /////////////////////////////////
                //////////////////////////////////////////////////////////////
                AppsFlyer.trackRichEvent("af_login", null);
                break;
            }
        }
コード例 #2
0
ファイル: IAPSDK.cs プロジェクト: IOTSY0447/FrameWork
        public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
        {
            m_PurchaseState = PurchaseState.NONE;
            Debug.Log(string.Format("SDK >> ProcessPurchase >> Product: '{0}'", args.purchasedProduct.definition.id));
            var productId  = args.purchasedProduct.definition.id;
            var notifyBody = new IAPSuccessResult();

            notifyBody.product = args.purchasedProduct;
            bool isRestore = this.m_RestoreState == RestoreState.RESTORING;

            if (isRestore)
            {
                this.m_RestoreState = RestoreState.DONE;
            }
            Config.ID.iap.ForEach(it => {
                // do something with entry.Value or entry.Key
                if (string.Equals(it.ID, productId) &&
                    it.Type == Config.PurchaseType.NonConsumable)
                {
                    // record purchase
                    WritePurchase(it.Key, productId);
                    notifyBody.productKey  = it.Key;
                    notifyBody.productItem = it;
                    notifyBody.isRestore   = isRestore;
                }
            });
            this.facade.SendNotification(IAP_MSG.PURCHASE_SUCCESS, notifyBody);
            if (isRestore)
            {
                this.facade.SendNotification(IAP_MSG.RESTORE_SUCCESS);
            }

            // Return a flag indicating whether this product has completely been received, or if the application needs
            // to be reminded of this purchase at next app launch. Use PurchaseProcessingResult.Pending when still
            // saving purchased products to the cloud, and when that save is delayed.
            return(PurchaseProcessingResult.Complete);
        }