You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何禁用iOS 17中Xamarin.iOS应用的Autofill弹窗?

解决iOS 17 Xamarin.iOS UITextField Autofill弹窗问题

方案一:设置文本框内容类型为无

对于不需要Autofill的UITextField,直接指定其TextContentType为UITextContentType.None,让iOS明确该输入框不需要自动填充:

yourTextField.TextContentType = UITextContentType.None;
// 可选:同时关闭自动校正和大写,避免其他无关交互
yourTextField.AutocorrectionType = UITextAutocorrectionType.No;
yourTextField.AutocapitalizationType = UITextAutocapitalizationType.None;

方案二:自定义上下文菜单移除Autofill选项

iOS 17中,该Autofill选项对应UIMenuIdentifier.Fill和UIMenuIdentifier.Passwords,在BuildMenu中移除这些菜单:

public override void BuildMenu(IUIMenuBuilder builder)
{
    base.BuildMenu(builder);
    
    if (UIDevice.CurrentDevice.CheckSystemVersion(17, 0))
    {
        // 移除填充相关菜单
        builder.RemoveMenu(UIMenuIdentifier.Fill);
        builder.RemoveMenu(UIMenuIdentifier.Passwords);
    }
    // 保留原有的Lookup移除逻辑
    if (UIDevice.CurrentDevice.CheckSystemVersion(16, 0))
    {
        builder.RemoveMenu(UIMenuIdentifier.Lookup);
    }
}

方案三:通过CanPerformAction拦截Autofill选择器

Autofill对应的选择器为_autofill:和fillContact:,在你的EvaluateEditSelector方法中添加这些case并返回false:

public bool EvaluateEditSelector(string selector) //gets called by CanPerformAction()
{
    if (AllowCopyPaste || CopyPasteOverride)
    {
        switch (selector)
        {
            case "cut:":
            case "copy:":
            case "select:":
            case "selectAll:":
            case "paste:":
                return showCopyPaste;
            case "makeTextWritingDirectionLeftToRight:":
                showCopyPaste = true;
                return false;
            // 添加Autofill相关选择器拦截
            case "_autofill:":
            case "fillContact:":
                return false;
            default:
                return false;
        }
    }
    else
    {
        return false;
    }
}

建议优先使用方案一,这是最符合iOS设计规范的方式,只有当方案一无效时再尝试方案二或三。

内容的提问来源于stack exchange,提问作者AlphaNERD

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 21:52:52