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

调用MFMessageComposeViewController的setUPIVerificationCodeSendCompletion方法报错求助

解决MFMessageComposeViewController无setUPIVerificationCodeSendCompletion成员的问题

出现这个错误,可从以下几个方向排查解决:

  • iOS版本适配问题:setUPIVerificationCodeSendCompletion 是iOS 17.0及以上版本才引入的API。如果你的项目部署目标(Deployment Target)低于iOS 17.0,要么提升部署目标,要么添加版本兼容判断:

    import MessageUI
    
    class SendSms {
        
        func createMessageController() -> UIViewController {
            let vc = MFMessageComposeViewController()
            if #available(iOS 17.0, *) {
                vc.setUPIVerificationCodeSendCompletion { result in
                    print("\(result)")
                }
            }
            return vc
        }
    }
    
  • 权限配置问题:确认com.apple.developer.upi-device-validation权限的配置流程正确:

    • 需在Xcode的「Signing & Capabilities」面板中添加该权限,避免手动修改Info.plist时出现格式错误;
    • 该权限需要向苹果申请授权,确保你的开发者账号已获得使用资格,未通过申请的话即使配置了也无法调用相关API。
  • SDK版本问题:确保你使用的Xcode版本支持iOS 17.0 SDK(至少Xcode 15.0及以上),旧版本Xcode的SDK中未包含这个方法,会直接报无成员错误。

  • 拼写校验:仔细核对方法名,确保没有拼写错误,官方正确方法名是setUPIVerificationCodeSendCompletion(_:),参数为MFMessageComposeViewController.UPIVerificationCodeSendCompletion类型的闭包。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 21:23:12