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
相关产品推荐
相关产品推荐

