Пример #1
0
        public void NamiSetup()
        {
            // This is the appID for a Nami test application with already configured products and paywalls, contact Nami to obtain an Application ID for your own application.
            var namiConfig = NamiConfiguration.ConfigurationForAppPlatformID(NAMI_APP_PLATFORM_ID);

            // Makes sure when the app is re-run that any stored bypass purchases are cleared out so we can retry purchases
            // Note this cannot clear out StoreKit sandbox or regular purchases, which Apple controls.
            // This only clears out purchases made when bypassStoreKit is enabled.
            NamiPurchaseManager.ClearBypassStorePurchases();

            // For testing we'll bypass StoreKit, so you don't have to run the app on a device to test purchases.
            // You may want to include some ability to toggle this on for testers of your application.
            namiConfig.BypassStore = true;

            //Nami recommends setting the log level to Warn for apps on the store. Info may be helpful during development to better understand what is going on. Debug level has a lot of information and is likely only helpful to the Nami support team.
            namiConfig.LogLevel = NamiLogLevel.Info;
            Nami.ConfigureWithNamiConfig(namiConfig);

            //sign in handler not currently being used but could be needed in the future
            NamiPaywallManager.RegisterSignInHandler((viewController, message, paywall) => {
                var okAlertController = UIAlertController.Create("Sign In", message, UIAlertControllerStyle.Alert);

                //Add Action
                okAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));

                // Present Alert
                UIApplication.SharedApplication.KeyWindow.RootViewController.PresentedViewController.PresentViewController(okAlertController, true, null);
            });


            //Nami triggers a callback any time there is a change to the state of an entitlement.
            //In the callback the full list of currently active entitlements is provided.
            //You can use this to store the state of whether a user has access to premium features locally in your app.
            NamiPurchaseManager.RegisterPurchasesChangedHandler(changeHandler: (purchases, purchaseState, error) => {
                foreach (NamiPurchase purchase in purchases)
                {
                    var expires = purchase.Expires;
                }
            });

            NamiPaywallManager.RegisterAllowAutoRaisePaywallHandler(() => { return(true); });
        }
Пример #2
0
        private void NamiSetup()
        {
            // Makes sure when the app is re-run that any stored bypass purchases are cleared out so we can retry purchases
            // Note this cannot clear out StoreKit sandbox or regular purchases, which Apple controls.
            // This only clears out purchases made when bypassStoreKit is enabled.
            NamiPurchaseManager.ClearBypassStorePurchases();

            // This is the appID for a Nami test application with already configured products and paywalls, contact Nami to obtain an Application ID for your own application.
            var namiConfig = NamiConfiguration.ConfigurationForAppPlatformID("002e2c49-7f66-4d22-a05c-1dc9f2b7f2af");

            // For testing we'll bypass StoreKit, so you don't have to run the app on a device to test purchases.
            // You may want to include some ability to toggle this on for testers of your application.
            namiConfig.BypassStore = true;

            namiConfig.LogLevel = NamiLogLevel.Warn;
            Nami.ConfigureWithNamiConfig(namiConfig);

            NamiPaywallManager.RegisterSignInHandler((viewController, message, paywall) => {
                var okAlertController = UIAlertController.Create("Sign In", message, UIAlertControllerStyle.Alert);

                //Add Action
                okAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));

                // Present Alert
                UIApplication.SharedApplication.KeyWindow.RootViewController.PresentedViewController.PresentViewController(okAlertController, true, null);

                Nami.SetExternalIdentifier(TEST_EXTERNAL_IDENTIFIER, NamiExternalIdentifierType.Uuid);
            });

            NamiPurchaseManager.RegisterPurchasesChangedHandler(changeHandler: (purchases, purchaseState, error) => {
                foreach (NamiPurchase purchase in purchases)
                {
                    var expires = purchase.Expires;
                }
            });

            NamiPurchaseManager.IsSKUIDPurchased("nami_monthly");

            NamiPaywallManager.RegisterAllowAutoRaisePaywallHandler(() => { return(true); });
        }
        private void BuildUI()
        {
            var titleView = new UIImageView(UIImage.FromBundle("nami_logo_white"))
            {
                BackgroundColor = new UIColor(red: 0.25f, green: 0.43f, blue: 0.49f, alpha: 1.00f),
                ContentMode     = UIViewContentMode.ScaleAspectFit,
            };

            base.NavigationItem.TitleView = titleView;

            nfloat h = 31.0f;
            nfloat w = View.Bounds.Width;

            View.BackgroundColor = UIColor.White;

            var aboutButton = UIButton.FromType(UIButtonType.RoundedRect);

            aboutButton.Frame = new CGRect(10, 50, w - 20, 44);
            aboutButton.SetTitle("About", UIControlState.Normal);
            aboutButton.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;

            var subscribeButton = UIButton.FromType(UIButtonType.RoundedRect);

            subscribeButton.Frame = new CGRect(10, 700, w - 20, 44);
            subscribeButton.SetTitle("Subscribe", UIControlState.Normal);
            subscribeButton.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;

            subscribeButton.TouchDown += OnSubscribeClicked;
            aboutButton.TouchDown     += OnAboutClicked;


            scrollView = new UIScrollView(new CGRect(0, 0, View.Frame.Width, View.Frame.Height));
            scrollView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
            scrollView.ContentSize      = new CGSize(View.Frame.Width, 760);

            scrollView.AddSubview(new UILabel(new CGRect(0, 0, View.Frame.Width, 50))
            {
                Text             = "BasicLinked",
                Font             = UIFont.BoldSystemFontOfSize(36),
                TextAlignment    = UITextAlignment.Center,
                AutoresizingMask = UIViewAutoresizing.FlexibleWidth
            });

            scrollView.AddSubview(aboutButton);

            scrollView.AddSubview(new UILabel(new CGRect(10, 120, View.Frame.Width, 50))
            {
                Text             = "Introduction",
                Font             = UIFont.BoldSystemFontOfSize(24),
                TextAlignment    = UITextAlignment.Left,
                TextColor        = UIColor.Black,
                AutoresizingMask = UIViewAutoresizing.FlexibleWidth
            });

            scrollView.AddSubview(new UILabel(new CGRect(10, 120, View.Frame.Width - 20, 150))
            {
                Text             = "This application demonstrates common calls used in a Nami enabled application.",
                Font             = UIFont.SystemFontOfSize(18),
                TextAlignment    = UITextAlignment.Left,
                TextColor        = UIColor.Black,
                AutoresizingMask = UIViewAutoresizing.All,
                LineBreakMode    = UILineBreakMode.WordWrap,
                Lines            = 0
            });


            scrollView.AddSubview(new UILabel(new CGRect(10, 250, View.Frame.Width - 20, 50))
            {
                Text             = "Instructions",
                Font             = UIFont.BoldSystemFontOfSize(24),
                TextAlignment    = UITextAlignment.Left,
                TextColor        = UIColor.Black,
                AutoresizingMask = UIViewAutoresizing.FlexibleWidth
            });

            scrollView.AddSubview(new UILabel(new CGRect(10, 260, View.Frame.Width - 20, 150))
            {
                Text             = "If you suspend and resume this app three times in the simulator, an example paywall will be raised - or you can use the Subscribe button below to raise the same paywall.",
                Font             = UIFont.SystemFontOfSize(18),
                TextAlignment    = UITextAlignment.Left,
                TextColor        = UIColor.Black,
                AutoresizingMask = UIViewAutoresizing.All,
                LineBreakMode    = UILineBreakMode.WordWrap,
                Lines            = 0
            });

            scrollView.AddSubview(new UILabel(new CGRect(10, 400, View.Frame.Width - 20, 50))
            {
                Text             = "Important Info",
                Font             = UIFont.BoldSystemFontOfSize(24),
                TextAlignment    = UITextAlignment.Left,
                TextColor        = UIColor.Black,
                AutoresizingMask = UIViewAutoresizing.FlexibleWidth
            });

            scrollView.AddSubview(new UILabel(new CGRect(10, 450, View.Frame.Width - 20, 150))
            {
                Text             = "Any Purchase will be remembered while the application is Active, Suspended, Resume, but cleared when the Application is launched.  \nExamine the application source code for more details on calls used to respond and monitor purchases.",
                Font             = UIFont.SystemFontOfSize(18),
                TextAlignment    = UITextAlignment.Left,
                TextColor        = UIColor.Black,
                AutoresizingMask = UIViewAutoresizing.All,
                LineBreakMode    = UILineBreakMode.WordWrap,
                Lines            = 0
            });

            subscriptionStatusLabel = new UILabel(new CGRect(10, 600, View.Frame.Width - 20, 50))
            {
                Text             = "Subscription is: Inactive",
                Font             = UIFont.BoldSystemFontOfSize(24),
                TextAlignment    = UITextAlignment.Left,
                TextColor        = UIColor.Black,
                AutoresizingMask = UIViewAutoresizing.FlexibleWidth
            };
            scrollView.AddSubview(subscriptionStatusLabel);

            scrollView.AddSubview(subscribeButton);

            this.View.AddSubview(scrollView);

            NamiEntitlementManager.RegisterEntitlementsChangedHandler((entitlements) =>
            {
                Console.WriteLine("Entitlements Change Listener triggered");

                var ent = new List <NamiEntitlement>();

                foreach (var n in entitlements)
                {
                    ent.Add(n);
                }

                LogActiveEntitlements(ent);

                HandleActiveEntitlements(ent);
            });

            NamiPurchaseManager.RegisterPurchasesChangedHandler((purchases, state, error) => {
                var pur = new List <NamiPurchase>();

                foreach (var n in purchases)
                {
                    pur.Add(n);
                }

                EvaluateLastPurchaseEvent(pur, state, error?.ToString());
            });

            HandleActiveEntitlements(NamiEntitlementManager.ActiveEntitlements().ToList());
        }
Пример #4
0
        /// <summary>
        /// This method sets up the user interface and creates the controls that should be rendered on the page
        /// </summary>
        public void SetupUserInterface()
        {
            var titleView = new UIImageView(UIImage.FromBundle("nami_logo_white"))
            {
                BackgroundColor = new UIColor(red: 0.25f, green: 0.43f, blue: 0.49f, alpha: 1.00f),
                ContentMode     = UIViewContentMode.ScaleAspectFit,
            };

            base.NavigationItem.TitleView = titleView;

            nfloat h = 31.0f;
            nfloat w = View.Bounds.Width;

            View.BackgroundColor = UIColor.White;

            var subscribeButton = UIButton.FromType(UIButtonType.RoundedRect);

            subscribeButton.Frame = new CGRect(10, 600, w - 20, 44);
            subscribeButton.SetTitle("Subscribe", UIControlState.Normal);
            subscribeButton.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;

            subscribeButton.TouchDown += OnSubscribeClicked;

            scrollView = new UIScrollView(new CGRect(0, 0, View.Frame.Width, View.Frame.Height));
            scrollView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
            scrollView.ContentSize      = new CGSize(View.Frame.Width, 760);

            subscriptionStatusLabel = new UILabel(new CGRect(10, 550, View.Frame.Width - 20, 50))
            {
                Text             = "Subscription is: Inactive",
                Font             = UIFont.BoldSystemFontOfSize(24),
                TextAlignment    = UITextAlignment.Left,
                TextColor        = UIColor.Black,
                AutoresizingMask = UIViewAutoresizing.FlexibleWidth
            };
            scrollView.AddSubview(subscriptionStatusLabel);

            scrollView.AddSubview(subscribeButton);

            this.View.AddSubview(scrollView);


            //Register a callback to react to a change in the state of entitlements for the user.
            //this fires after the RegisterPurchasesChangedHandler
            NamiEntitlementManager.RegisterEntitlementsChangedHandler((entitlements) =>
            {
                Console.WriteLine("Entitlements Change Listener triggered");

                var ent = new List <NamiEntitlement>();

                foreach (var n in entitlements)
                {
                    ent.Add(n);
                }

                LogActiveEntitlements(ent);

                HandleActiveEntitlements(ent);
            });

            //register a handler to listen for changes
            //it is important to check the state of the purchase as there are multiple states that can result in this event getting triggered.
            NamiPurchaseManager.RegisterPurchasesChangedHandler((purchases, state, error) => {
                var pur = new List <NamiPurchase>();

                foreach (var n in purchases)
                {
                    pur.Add(n);
                }

                EvaluateLastPurchaseEvent(pur, state, error?.ToString());
            });

            HandleActiveEntitlements(NamiEntitlementManager.ActiveEntitlements().ToList());
        }