Exemplo n.º 1
0
        public async Task <SKProductsResponse> RequestProductData(params string[] productIds)
        {
            var array = new NSString[productIds.Length];

            for (var i = 0; i < productIds.Length; i++)
            {
                array[i] = new NSString(productIds[i]);
            }

            var tcs = new TaskCompletionSource <SKProductsResponse>();

            _productDataRequests.AddLast(tcs);

            try
            {
                var productIdentifiers = NSSet.MakeNSObjectSet <NSString>(array); //NSSet.MakeNSObjectSet<NSString>(array);​​​
                var productsRequest    = new SKProductsRequest(productIdentifiers);
                productsRequest.ReceivedResponse += (sender, e) => tcs.SetResult(e.Response);
                productsRequest.RequestFailed    += (sender, e) => tcs.SetException(new Exception(e.Error.LocalizedDescription));
                productsRequest.Start();
                var ret = await tcs.Task;
                productsRequest.Dispose();
                return(ret);
            }
            finally
            {
                _productDataRequests.Remove(tcs);
                Console.WriteLine("Remaining: " + _productDataRequests.Count);
            }
        }
Exemplo n.º 2
0
        protected override void Initialize()
        {
            base.Initialize();

            // all HealthKit permissions were requested in a single batch when the protocol was started; however, HealthKit probes
            // can also be started individually after the protocol is started by toggling Enabled on the probe page. in such cases
            // we want to request permission for the HealthKit probe that was just started. if the permission associated with this
            // probe was already requested, these calls will have no effect. even if the user previously denied access for this probe
            // these calls will not do anything by design by iOS. however, if the user has never been prompted for the permission
            // associated with this probe (i.e., the user is starting the probe by toggling Enabled), then the user will be prompted.
            if (HKHealthStore.IsHealthDataAvailable)
            {
                NSSet            objectTypesToRead = NSSet.MakeNSObjectSet <HKObjectType>(new HKObjectType[] { ObjectType });
                ManualResetEvent authorizationWait = new ManualResetEvent(false);
                _healthStore.RequestAuthorizationToShare(new NSSet(), objectTypesToRead,
                                                         (success, error) =>
                {
                    if (error != null)
                    {
                        SensusServiceHelper.Get().Logger.Log("Error while requesting HealthKit authorization:  " + error.Description, LoggingLevel.Normal, GetType());
                    }

                    authorizationWait.Set();
                });

                authorizationWait.WaitOne();
            }
        }
Exemplo n.º 3
0
        public async Task <SKProductsResponse> RequestProductData(params string[] productIds)
        {
            var array = new NSString[productIds.Length];

            for (var i = 0; i < productIds.Length; i++)
            {
                array[i] = new NSString(productIds[i]);
            }

            var tcs = new TaskCompletionSource <SKProductsResponse>();

            _productDataRequests.AddLast(tcs);

            try
            {
                var productIdentifiers = NSSet.MakeNSObjectSet <NSString>(array); //NSSet.MakeNSObjectSet<NSString>(array);​​​
                var productsRequest    = new SKProductsRequest(productIdentifiers);
                productsRequest.ReceivedResponse += (sender, e) => tcs.SetResult(e.Response);
                productsRequest.RequestFailed    += (sender, e) => tcs.SetException(new Exception(e.Error.LocalizedDescription));
                productsRequest.Start();
                if (await Task.WhenAny(tcs.Task, Task.Delay(TimeSpan.FromSeconds(30))) != tcs.Task)
                {
                    throw new InvalidOperationException("Timeout waiting for Apple to respond");
                }
                var ret = tcs.Task.Result;
                productsRequest.Dispose();
                return(ret);
            }
            finally
            {
                _productDataRequests.Remove(tcs);
            }
        }
Exemplo n.º 4
0
        public void requestProUpgradeProductData()
        {
            NSSet productIdentifiers = NSSet.MakeNSObjectSet <NSString>(new NSString[] { new NSString(InAppPurchaseProUpgradeProductId) });

            productsRequest          = new SKProductsRequest(productIdentifiers);
            productsRequest.Delegate = this;
            productsRequest.Start();
        }
Exemplo n.º 5
0
        NSSet DataTypesToRead(HealthDataType[] dataTypes)
        {
            var types = new HKObjectType[dataTypes.Length];

            for (var i = 0; i < dataTypes.Length; i++)
            {
                types.SetValue(HKQuantityType.Create(dataTypes[i].ToHealthKit().TypeIdentifier), i);
            }
            return(NSSet.MakeNSObjectSet(types));
        }
Exemplo n.º 6
0
        // request multiple products at once
        public void RequestProductData(List <string> productIds)
        {
            NSString[] array = productIds.Select(pId => (NSString)pId).ToArray();
            NSSet      productIdentifiers = NSSet.MakeNSObjectSet <NSString>(array);

            //set up product request for in-app purchase
            ProductsRequest          = new SKProductsRequest(productIdentifiers);
            ProductsRequest.Delegate = this;             // SKProductsRequestDelegate.ReceivedResponse
            ProductsRequest.Start();
        }
Exemplo n.º 7
0
        public Task <SKProductsResponse> FetchProductInformationAsync(string[] ids)
        {
            var request = new SKProductsRequest(
                NSSet.MakeNSObjectSet(ids.Select(x => new NSString(x)).ToArray()));
            var del = new TaskRequestDelegate();

            request.Delegate = del;
            request.Start();
            return(del.Task);
        }
        public override void Selected(DialogViewController dvc, UITableView tableView, NSIndexPath path)
        {
            /*var vc = new MapKitViewController (this) {
             *      Autorotate = dvc.Autorotate
             * };*/

            NetworkActivity = true;
            if (SKPaymentQueue.CanMakePayments)
            {
                // Let's do it
                NSSet productIdentifiers = NSSet.MakeNSObjectSet <NSString>(/*new NSString[]{new NSString("com.savagesoftwaresolutions.murdermap.subscription.monthly"), new NSString("com.savagesoftwaresolutions.com.murdermap.monthly")}*/ ProductIdentifiers);
                var   request            = new SKProductsRequest(productIdentifiers);

                request.ReceivedResponse += delegate(object sender, SKProductsRequestResponseEventArgs e)
                {
                    var root         = new RootElement(Caption);
                    var dvStore      = new DialogViewController(root, true);
                    var storeSection = new Section();

                    root.Add(storeSection);


                    foreach (var product in e.Response.Products)
                    {
                        storeSection.Add(new StringElement(product.LocalizedTitle + ":" + product.PriceLocale));
                    }

                    dvc.ActivateController(dvStore);
                };

                request.RequestFailed += delegate(object sender, SKRequestErrorEventArgs e)
                {
                    using (var msg = new UIAlertView("Request Failed", e.Error.ToString(), null, "Ok")){
                        msg.Show();
                    }
                };

                request.RequestFinished += delegate(object sender, EventArgs e) {
                    NetworkActivity = false;
                };

                request.Start();
            }
            else
            {
                using (var msg = new UIAlertView("Unabled to Make Payments", "We are unable to connect to the Apple Store at this moment, to process your payments.\n Please try again later.", null, "Ok")){
                    msg.Show();
                }
            }

            NetworkActivity = false;
        }
Exemplo n.º 9
0
        NSSet DataTypesToPermissions(HealthDataType[] dataTypes)
        {
            var types = new HKObjectType[dataTypes.Length];

            for (var i = 0; i < dataTypes.Length; i++)
            {
                var dataType = dataTypes[i].ToHealthKit();

                types.SetValue(dataType.Permission, i);
            }

            return(NSSet.MakeNSObjectSet(types));
        }
Exemplo n.º 10
0
        public void QueryInventory()
        {
            var array = new NSString[1];

            array[0] = new NSString(this.PracticeModeProductId);
            NSSet productIdentifiers = NSSet.MakeNSObjectSet <NSString>(array);

            // Set up product request for in-app purchase to be handled in
            // SKProductsRequestDelegate.ReceivedResponse (see above)
            this._productsRequest          = new SKProductsRequest(productIdentifiers);
            this._productsRequest.Delegate = this;
            this._productsRequest.Start();
        }
Exemplo n.º 11
0
        public void RequestProductData(List <string> productIds)
        {
            var array = new NSString[productIds.Count];

            for (var i = 0; i < productIds.Count; i++)
            {
                array[i] = new NSString(productIds[i]);
            }
            NSSet productIdentifiers = NSSet.MakeNSObjectSet <NSString> (array);

            productsRequest          = new SKProductsRequest(productIdentifiers);
            productsRequest.Delegate = this;
            productsRequest.Start();
        }
Exemplo n.º 12
0
        Task <SKProduct> GetProductAsync(string productId)
        {
            var productIdentifiers = NSSet.MakeNSObjectSet <NSString>(new NSString[] { new NSString(productId) });

            var productRequestDelegate = new ProductRequestDelegate();

            //set up product request for in-app purchase
            var productsRequest = new SKProductsRequest(productIdentifiers);

            productsRequest.Delegate = productRequestDelegate; // SKProductsRequestDelegate.ReceivedResponse
            productsRequest.Start();

            return(productRequestDelegate.WaitForResponse());
        }
        Task <IEnumerable <SKProduct> > GetProductAsync(string[] productId)
        {
            var productIdentifiers = NSSet.MakeNSObjectSet <NSString>(productId.Select(i => new NSString(i)).ToArray());

            var productRequestDelegate = new ProductRequestDelegate();

            //set up product request for in-app purchase
            var productsRequest = new SKProductsRequest(productIdentifiers);

            productsRequest.Delegate = productRequestDelegate; // SKProductsRequestDelegate.ReceivedResponse
            productsRequest.Start();

            return(productRequestDelegate.WaitForResponse());
        }
Exemplo n.º 14
0
        // request multiple products at once
        public void RequestProductData(List <string> productIds)
        {
            var array = new NSString[productIds.Count];

            for (var i = 0; i < productIds.Count; i++)
            {
                array[i] = new NSString(productIds[i]);
            }
            NSSet productIdentifiers = NSSet.MakeNSObjectSet <NSString>(array);

            //set up product request for in-app purchase
            productsRequest          = new SKProductsRequest(productIdentifiers);
            productsRequest.Delegate = this;             // SKProductsRequestDelegate.ReceivedResponse
            productsRequest.Start();
        }
        /// <summary>
        /// Returns product info for the specified Ids
        /// </summary>
        /// <param name="productIds">Product Ids</param>
        /// <param name="productType">Product Type - not used for iOS</param>
        /// <returns></returns>
        public async Task <IEnumerable <Product> > LoadProductsAsync(string[] productIds, ProductType productType)
        {
            NSString[] nsProductIds = productIds.Select(i => new NSString(i)).ToArray();
            // Try to get Product List from the Store
            NSSet nsSetOfproductIds = NSSet.MakeNSObjectSet <NSString>(nsProductIds);

            // Create a Delegeate which will receieve product data.
            // The callback is async, so the TaskCompletionSource is used to wait for App Store to respond.
            ProductRequestDelegate productRequestDelegate = new ProductRequestDelegate();

            // Set up product request for in-app purchase
            SKProductsRequest productsRequest = new SKProductsRequest(nsSetOfproductIds);

            productsRequest.Delegate = productRequestDelegate;

            /* Here is how the EventHadler could be used instead of the Delegate
             * productsRequest.ReceivedResponse += (object sender, SKProductsRequestResponseEventArgs e) =>
             * {
             *  var products = e.Response.Products;
             *  var product = products[0];
             *  Console.WriteLine(
             *      $"{product.ProductIdentifier}, " +
             *      $"{product.LocalizedDescription}," +
             *      $"{product.PriceLocale.CurrencySymbol}{product.Price}");
             *
             *  //product.Discounts
             * };*/

            // Start the StoreKit Request. Products will be sent back to the Delegate function(s)
            productsRequest.Start();

            // Wait for the Delegate to get Products and signal the Task to be complete
            // For more about TaskCompletionSource read: https://devblogs.microsoft.com/pfxteam/the-nature-of-taskcompletionsourcetresult/
            SKProduct[] products = await productRequestDelegate.WaitForResponse();

            return(products.Select(p => new Product
            {
                FormattedPrice = p.LocalizedPrice(),
                MicrosPrice = (long)(p.Price.DoubleValue * 1000000d),
                Name = p.LocalizedTitle,
                ProductId = p.ProductIdentifier,
                Description = p.LocalizedDescription,
                CurrencyCode = p.PriceLocale?.CurrencyCode ?? string.Empty,
                LocalizedIntroductoryPrice = IsiOS112 ? (p.IntroductoryPrice?.LocalizedPrice() ?? string.Empty) : string.Empty,
                MicrosIntroductoryPrice = IsiOS112 ? (long)((p.IntroductoryPrice?.Price?.DoubleValue ?? 0) * 1000000d) : 0,
            }));
        }
Exemplo n.º 16
0
        public static async Task <SKProductsResponse> RequestProductData(params string[] productIds)
        {
            var array = new NSString[productIds.Length];

            for (var i = 0; i < productIds.Length; i++)
            {
                array[i] = new NSString(productIds[i]);
            }

            var tcs = new TaskCompletionSource <SKProductsResponse>();
            var productIdentifiers = NSSet.MakeNSObjectSet <NSString>(array); //NSSet.MakeNSObjectSet<NSString>(array);​​​
            var productsRequest    = new SKProductsRequest(productIdentifiers);

            productsRequest.ReceivedResponse += (sender, e) => tcs.SetResult(e.Response);
            productsRequest.RequestFailed    += (sender, e) => tcs.SetException(new Exception(e.Error.LocalizedDescription));
            productsRequest.Start();
            return(await tcs.Task);
        }
Exemplo n.º 17
0
        protected override async Task InitializeAsync()
        {
            await base.InitializeAsync();

            if (HKHealthStore.IsHealthDataAvailable)
            {
                NSSet objectTypesToRead = NSSet.MakeNSObjectSet <HKObjectType>(new HKObjectType[] { ObjectType });

                Tuple <bool, NSError> successError = await _healthStore.RequestAuthorizationToShareAsync(new NSSet(), objectTypesToRead);

                if (!successError.Item1)
                {
                    string message = "Failed to request HealthKit authorization:  " + (successError.Item2?.ToString() ?? "[no details]");
                    SensusServiceHelper.Get().Logger.Log(message, LoggingLevel.Normal, GetType());
                    throw new Exception(message);
                }
            }
        }
Exemplo n.º 18
0
        private void RequestProductDetails()
        {
            if (this.products.Values.All(o => o.HasValidCache() || o.State == ProductState.Invalid || o.State == ProductState.Purchased))
            {
                return;
            }

            // If an existing request is in then progress cancel it
            var currentRequest = this.productsRequest;

            if (currentRequest != null)
            {
                currentRequest.Cancel();
            }

            var productIdentifiers = NSSet.MakeNSObjectSet <NSString>(
                this.products.Where(o => o.Value.State == ProductState.Loaded || o.Value.State == ProductState.Unknown).Select(o => new NSString(o.Key)).ToArray());

            this.productsRequest          = new SKProductsRequest(productIdentifiers);
            this.productsRequest.Delegate = this.productsRequestDelegate; // SKProductsRequestDelegate.ReceivedResponse
            this.productsRequest.Start();
        }
Exemplo n.º 19
0
            public async Task <SKProductsResponse> GetProductData(params string[] appStoreProductIDs)
            {
                _response = null;
                _error    = null;
                _waiter.Reset();


                if (appStoreProductIDs.Length == 0)
                {
                    throw new ArgumentException("No app store product IDs passed", "appStoreProductIDs");
                }
                var array = new NSString[appStoreProductIDs.Length];

                for (var i = 0; i < appStoreProductIDs.Length; i++)
                {
                    array[i] = new NSString(appStoreProductIDs[i]);
                }
                var productIdentifiers = NSSet.MakeNSObjectSet <NSString>(array);

                //set up product request for in-app purchase
                var productsRequest = new SKProductsRequest(productIdentifiers);

                productsRequest.Delegate = this;
                productsRequest.Start();
                await Task.Run(() => _waiter.Wait());


                if (_response != null)
                {
                    return(_response);
                }

                if (_error != null)
                {
                    throw new Exception(_error.LocalizedDescription);
                }

                throw new Exception("Unable to get product data due to unexpected cancellation of request");
            }
        public async Task Connect()
        {
            NSSet readTypes = NSSet.MakeNSObjectSet(new HKObjectType[]
            {
                StepType,
                DistanceType,
                BasalCaloriesType,
                ActiveCaloriesType,
                ActiveTimeType
            });

            try
            {
                if (HKHealthStore.IsHealthDataAvailable)
                {
                    Tuple <bool, NSError> success = await _healthStore.RequestAuthorizationToShareAsync(new NSSet(), readTypes);

                    IsConnected = success.Item1;

                    if (IsConnected)
                    {
                        OnConnect?.Invoke();
                    }
                    else
                    {
                        OnError?.Invoke(success.Item2.Description);
                    }
                }
                else
                {
                    OnError?.Invoke("Is_Health_Data_not_Available".ToUpper());
                }
            }
            catch (Exception e)
            {
                OnError?.Invoke(e.Message);
            }
        }
Exemplo n.º 21
0
        public async Task <SKProductsResponse> GetProductData(params string[] appStoreProductIDs)
        {
            if (appStoreProductIDs.Length == 0)
            {
                throw new ArgumentException("No app store product IDs passed", "appStoreProductIDs");
            }
            var array = new NSString[appStoreProductIDs.Length];

            for (var i = 0; i < appStoreProductIDs.Length; i++)
            {
                array[i] = new NSString(appStoreProductIDs[i]);
            }
            var productIdentifiers = NSSet.MakeNSObjectSet <NSString>(array);

            //set up product request for in-app purchase
            var productsRequest = new SKProductsRequest(productIdentifiers);

            productsRequest.Delegate = this;
            productsRequest.Start();
            await Task.Run(() => _waiter.Wait());

            Debug.Assert(_response != null);
            return(_response);
        }
Exemplo n.º 22
0
        // request multiple products at once
        public void RequestProductData(List <string> productIds)
        {
            try
            {
                Logger.Log("RequestProductData...");
                var array = new NSString[productIds.Count];
                for (var i = 0; i < productIds.Count; i++)
                {
                    array[i] = new NSString(productIds[i]);
                    Logger.Log("RequestProductData: Product ID: " + productIds[i]);
                }

                NSSet productIdentifiers = NSSet.MakeNSObjectSet <NSString>(array);

                //set up product request for in-app purchase
                productsRequest          = new SKProductsRequest(productIdentifiers);
                productsRequest.Delegate = this;
                productsRequest.Start();
            }
            catch (Exception ex)
            {
                Logger.Log("ERROR: RequestProductData: " + ex);
            }
        }
        private void ShowSurveyWithTagXamarin(object sender, EventArgs e)
        {
            NSSet tags = NSSet.MakeNSObjectSet <NSString> (new NSString [] { new NSString("xamarin") });

            ATSurveys.PresentSurveyController(tags, this);
        }
Exemplo n.º 24
0
        public CTFontDescriptor GetMatchingFontDescriptor(params NSString[] mandatoryAttributes)
        {
            NSSet attrs = NSSet.MakeNSObjectSet(mandatoryAttributes);

            return(GetMatchingFontDescriptor(attrs));
        }
Exemplo n.º 25
0
 public void SetHiddenKeys(NSString[] hiddenKeys, bool animated)
 {
     SetHiddenKeys(hiddenKeys == null ? null : NSSet.MakeNSObjectSet(hiddenKeys), animated);
 }