每当我尝试在模拟器上启动拍摄照片的页面时,我都会收到System.NotImplementedException错误。每当我尝试使用模拟器的相机拍照时,我都会进入启动用户界面的Xamarin Studio项目的主页面。我收到错误:
已抛出System.NotImplementedException
此程序集的可移植版本中未实现此功能。您应该从主应用程序项目中引用NuGet包,以引用特定于平台的实现。
以下是代码:
using UIKit;
namespace Relate.iOS
{
public class Application
{
// This is the main entry point of the application.
static void Main(string[] args)
{
/* if you want to use a different Application Delegate class
from "AppDelegate" you can specify it here. */
UIApplication.Main(args, null, "AppDelegate");
}
}
}
有人可以帮忙吗?
这是相机的代码。我在我的项目中添加了Media Plugin。
using System;
using Relate.Model;
using Xamarin.Forms;
using Plugin.Media;
namespace Relate.Views
{
public partial class EditMemberPage : ContentPage
{
public EditMemberPage()
{
InitializeComponent();
saveButton.Clicked += async (sender, args) =>
{
if (CrossMedia.Current.IsCameraAvailable &&
CrossMedia.Current.IsTakePhotoSupported)
{
// Supply media options for saving our photo after
it's taken.
var mediaOptions = new
Plugin.Media.Abstractions.StoreCameraMediaOptions
{
Directory = "Receipts",
Name = $"{DateTime.UtcNow}.jpg"
};
// Take a photo of the business receipt.
var file = await
CrossMedia.Current.TakePhotoAsync(mediaOptions);
}
};
}
async void SaveButton_OnClicked(object sender, EventArgs e)
{
var famMemberItem = (FamMember)BindingContext;
await App.Database.SaveFamMemberAsync(famMemberItem);
await Navigation.PopAsync();
}
}
}
答案 0 :(得分:0)
这里的答案应该解释为什么这不适合你:https://forums.xamarin.com/discussion/93536/error-while-accessing-camera
您无法使用便携式公共库访问特定于平台的功能。如果您想访问您的仿真器相机,您将不得不使用Media Plugin之类的东西 https://github.com/jamesmontemagno/MediaPlugin