MK *_*lan 2 xamarin.ios xamarin.forms wallet
我已成功创建 .pkpass 文件,并且 api 成功返回 .pkpass 文件。在 Xamarin 表单中,我使用 API 并尝试将 .pkpass 文件添加到钱包中,但钱包不会自动启动。
通过 Xamarin 应用程序从 api 使用的文件工作正常,文件没有问题。我已将其作为电子邮件附件发送并下载了附件 - .pkpass 文件会自动使用钱包应用程序打开。
public async Task DigitalMembershipCardApple()
{
string accesstoken = _dataHelper.GetAccessTokenFromDBAsync().Result;
try
{
_oHttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accesstoken);
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);
if (File.Exists(filePath))
{
File.Delete(filePath);
File.WriteAllBytes(filePath, filebytes);
}
else
{
File.WriteAllBytes(filePath, filebytes);
}
await Launcher.OpenAsync(new OpenFileRequest
{
File = new ReadOnlyFile(filePath, Constants.CISIMembershipCardFields.MimeTypeApple)
});
}
catch (Exception ex)
{
Debug.WriteLine(ex.StackTrace);
throw ex;
}
}
Run Code Online (Sandbox Code Playgroud)
我还使用了 Xamarin 基本启动器,但这没有帮助。
小智 6
//Called from Xamarin Forms, now on iOS Project,
public async void AddToWallet(byte[] passByteArray)
{
NSData nsdata = NSData.FromArray(passByteArray);
NSError err = new NSError(new NSString("42"), -42);
PKPass newPass = new PKPass(nsdata, out err);
PKAddPassesViewController pkapvc = new PKAddPassesViewController(newPass);
await UIApplication.SharedApplication.KeyWindow.RootViewController.
PresentViewControllerAsync(pkapvc, true);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
945 次 |
| 最近记录: |