错误CS0246:类型或名称空间名称' uikit'做CI构建时找不到

发布于 2025-01-18 13:00:33 字数 596 浏览 0 评论 0原文

Uikit将在我的解决方案中的iOS项目中构建我的CI构建,但不会在我的共同项目中构建, 在此处输入图像描述

它给了我上面指出的错误。任何想法为什么。我需要在iPone上执行警报,因为app.current.mainpage.displayalert和popupNavigation.instance.pushasync(new Popuppage());利用RG.Plugins.popup.pages.popuppage无法正常工作,但是我知道Uikit工作中的警报,因为它们可以使用我拥有的另一个iOS应用程序。

哦,顺便说一句,这是在本地构建的,只是在我的CI构建上不是

我的CI构建的YAML,这是非常基本的

步骤: - 任务:Xamarinios@2 DisplayName:“构建解决方案” 输入: SolutionFile:mileagemanagerforms.sln 配置:“临时” 干净:是的 WorkingDirectory:mileagemanagerforms/mileagemanagerforms.ios

UIKit will build in my CI build in my IOS project in my solution but will not build in my common project noted here,
enter image description here

it gives me the error noted above. Any idea why. I need this to do alerts on my ipone because the App.Current.MainPage.DisplayAlert and the PopupNavigation.Instance.PushAsync(new PopupPage()); utilizing the Rg.Plugins.Popup.Pages.PopupPage are not working, but I know the alerts in the UIKit work as they work on another IOS app that I have.

Oh, and by the way, this builds locally, just not on my CI build

Here is my yaml for the CI build, very basic

steps:
- task: XamariniOS@2
displayName: 'Build Solution '
inputs:
solutionFile: MileageManagerForms.sln
configuration: 'Ad-Hoc'
clean: true
workingDirectory: MileageManagerForms/MileageManagerForms.iOS

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剧终人散尽 2025-01-25 13:00:33

确保您添加了Uikit汇编正确参考。

per

”或找不到程序中使用的名称空间。您可能已经忘记参考包含类型的程序集( - 参考),或者您可能没有使用指令添加所需的内容。或者,您要引用的组件可能存在问题。

使用uialertControllerStyle指示要显示的警报的类型。这些警报类型是:

•   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/ os/ oser/user-interface/controls/controls/alerts/alerts/alerts

更新:
有一个解决方法可以使用 /a>在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);

Make sure you have added UIKit assembly reference correctly.

Per Microsoft docs :

A type or namespace that is used in the program was not found. You might have forgotten to reference (-reference) the assembly that contains the type, or you might not have added the required using directive. Or, there might be an issue with the assembly you are trying to reference.

Use UIAlertControllerStyle to indicate the type of alert to display.These alerts types are:

•   UIAlertControllerStyleActionSheet
•   UIAlertControllerStyleAlert
        

The code to display a simple alert is as follows:

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);
};

Reference link: https://learn.microsoft.com/en-us/xamarin/ios/user-interface/controls/alerts

Update:
There is a workaround that use dependency service to set the alert on the iOS project.

1.Create an interface in our shared package.

public interface IMessage
{
    void LongAlert(string message);
    void ShortAlert(string message);
}

2.In iOS project,we should implement it.

[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();
        }
    }
}
}

The you can get the alert service in anywhere in our project.

DependencyService.Get<IMessage>().ShortAlert(string message); 
DependencyService.Get<IMessage>().LongAlert(string message);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文