UIKit将在我的CI构建中构建在我的解决方案中的IOS项目中,但不会构建在我这里提到的普通项目中,在这里输入图像描述
这给了我上面提到的错误。知道原因吗。我需要它在我的ipone上做警报,因为App.Current.MainPage.DisplayAlert和PopupNavigation.Instance.PushAsync(新的PopupPage());使用Rg.Plugins.Popup.Pages.PopupPage不起作用,但是我知道UIKit中的警报是在我的另一个IOS应用程序上工作的。
哦,顺便说一句,这是在本地建立的,只是不是在我的CI构建上。
这是我的CI构建的yaml,非常基本
步骤:任务: XamariniOS@2 displayName:‘构建解决方案’输入: solutionFile: MileageManagerForms.sln配置:‘Ad’干净: true workingDirectory: MileageManagerForms/MileageManagerForms.iOS
发布于 2022-04-04 09:30:46
确保正确添加了UIKit
程序集引用。
根据微软文档:
找不到程序中使用的类型或命名空间。您可能忘记引用(-reference)包含类型的程序集,或者您可能没有使用指令添加所需的程序集。或者,您要引用的程序集可能有问题。
使用UIAlertControllerStyle指示对display.These警报类型的警报类型如下:
• UIAlertControllerStyleActionSheet
• UIAlertControllerStyleAlert
显示简单警报的代码如下所示:
okayButton.TouchUpInside += (sender, e) => {
//Create Alert
var okAlertController = UIAlertController.Create ("Title", "The message", UIAlertControllerStyle.Alert);
//Add Action
okAlertController.AddAction (UIAlertAction.Create ("OK", UIAlertActionStyle.Default, null));
// Present Alert
PresentViewController (okAlertController, true, null);
};
参考链接:https://learn.microsoft.com/en-us/xamarin/ios/user-interface/controls/alerts
更新:有一个解决办法,使用依赖服务设置iOS项目的警报。
1.在共享包中创建一个接口。
public interface IMessage
{
void LongAlert(string message);
void ShortAlert(string message);
}
2.在iOS项目中,我们应该实施它。
[assembly: Xamarin.Forms.Dependency(typeof(MessageIOS))]
namespace Your.Namespace
{
public class MessageIOS : IMessage
{
const double LONG_DELAY = 3.5;
const double SHORT_DELAY = 2.0;
NSTimer alertDelay;
UIAlertController alert;
public void LongAlert(string message)
{
ShowAlert(message, LONG_DELAY);
}
public void ShortAlert(string message)
{
ShowAlert(message, SHORT_DELAY);
}
void ShowAlert(string message, double seconds)
{
alertDelay = NSTimer.CreateScheduledTimer(seconds, (obj) =>
{
dismissMessage();
});
alert = UIAlertController.Create(null, message, UIAlertControllerStyle.Alert);
UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(alert, true, null);
}
void dismissMessage()
{
if (alert != null)
{
alert.DismissViewController(true, null);
}
if (alertDelay != null)
{
alertDelay.Dispose();
}
}
}
}
您可以在我们项目的任何地方获得警报服务。
DependencyService.Get<IMessage>().ShortAlert(string message);
DependencyService.Get<IMessage>().LongAlert(string message);
https://stackoverflow.com/questions/71718489
复制相似问题