问题
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