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

iOS调用GIDSignIn.sharedInstance提示非函数无法访问clientID如何解决

报错原因

该问题是GoogleSignIn SDK版本迭代导致的API语法不兼容:

  • 5.x及更早版本的GoogleSignIn中,sharedInstance是类方法,需要加括号调用
  • 6.0及更高版本的GoogleSignIn中,sharedInstance调整为静态属性,不需要加括号调用
解决方案

根据你使用的SDK版本选择对应修正方式即可:

  • 若使用6.0及以上版本GoogleSignIn
    直接移除sharedInstance后的括号,修改对应代码为:
import UIKit
import GoogleSignIn

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        GIDSignIn.sharedInstance.clientID = "替换为你的实际clientID"
        return true
    }
}

如果修改后仍有报错,执行pod deintegrate && pod install清理本地依赖缓存后重新编译即可。

  • 若项目依赖兼容要求必须使用5.x及更早版本
    在Podfile中指定SDK版本:
pod 'GoogleSignIn', '~> 5.0'

执行pod install后原有带括号的写法即可正常运行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.06 11:51:01