How to open a pkpass file to wallet from Xamarin Mobile application

寵の児 提交于 2020-01-25 08:55:08

问题


I have created pkpass file from server side and its working fine. I try to consume the pkpass via service and try to add the pass via PKAddPassesViewController. But it's not working. I have followed this resourse to add pass file to add wallet

  try
        {
            _oHttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accesstoken);

            //this response is pkpass file
            HttpResponseMessage response = await _oHttpClient.GetAsync(new Uri(Constants.Urls.DigitalMembershipCardApple + _dataHelper.GetPersonID()));

            byte[] filebytes = await response.Content.ReadAsByteArrayAsync();

            string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), Constants.CISIMembershipCardFields.FileDownloadName);

            string builtInPassPath = Path.Combine(System.Environment.CurrentDirectory, "cisi.pkpass");

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
                File.WriteAllBytes(filePath, filebytes);
                //File.Copy(builtInPassPath, filePath);
            }
            else
            {
                File.Copy(builtInPassPath, filePath);
                File.WriteAllBytes(filePath, filebytes);
            }

            NSData nsdata;
            using (FileStream oStream = File.Open(filePath, FileMode.Open))
            {
                nsdata = NSData.FromStream(oStream);
            }

            NSError err = new NSError(new NSString("42"), -42);
            PKPass newPass = new PKPass(nsdata, out err);

            PKAddPassesViewController pkapvc = new PKAddPassesViewController(newPass);
            UINavigationController navigationController = new UINavigationController();

            navigationController.PresentModalViewController(pkapvc, true);             


        }
        catch (Exception ex)
        {
            Debug.WriteLine("exeption for pk pass");
            Debug.WriteLine(ex.StackTrace);
            throw ex;
        }

来源:https://stackoverflow.com/questions/59069438/how-to-open-a-pkpass-file-to-wallet-from-xamarin-mobile-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!