我已经从服务器端创建了pkpass文件,它的工作正常。我尝试通过服务使用pkpass,并尝试通过PKAddPassesViewController添加通行证。但这不起作用。我遵循了this的资源来添加通行证文件来添加钱包
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;
}