Ken*_*ihe 6 ios firebase swift firebase-authentication
我在这里按照指南使用Firebase开发iOS应用程序。从字面上看,这是我进入iOS开发的第一天,所以首先我想问问是否有人有任何出色的iOS Swift开发教科书或教程?
遵循指南(在链接中)后,到处都出现此错误, use of undeclared type GIDSignInDelegate
例如,在AppDelegate类声明中...
class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate, GIDSignInDelegate {
我在类声明中看到了其他类型,例如UIResponder和UIApplicationDelegate。这些类型在哪里定义?
我猜想我只是在缺少类型定义。
我创建了一个头文件Basketball-Vision-Bridging-Header.h并导入#import <GoogleSignIn/GoogleSignIn.h>
我是否必须以某种方式链接该文件?
我已将以下内容添加到我的 Podfile
pod 'Firebase'
pod 'Firebase/Auth'
pod 'GoogleSignIn'
Run Code Online (Sandbox Code Playgroud)
更新
我发现我缺少这些依赖项:
import Google
import GoogleSignIn
Run Code Online (Sandbox Code Playgroud)
但是现在当我导入这些时,我得到了错误 type 'AppDelegate' does not conform to protocol 'GIDSignInDelegate'
这是完整的代码 AppDelegate
import UIKit
import Firebase
import Google
import GoogleSignIn
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate, GIDSignInDelegate {
var window: UIWindow?
func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!,
withError error: NSError!) {
if let error = error {
print(error.localizedDescription)
return
}
// ...
}
func signIn(signIn: GIDSignIn!, didDisconnectWithUser user:GIDGoogleUser!,
withError error: NSError!) {
// Perform any operations when the user disconnects from app here.
// ...
}
func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?)
-> Bool {
// Use Firebase library to configure APIs
FIRApp.configure()
GIDSignIn.sharedInstance().clientID = FIRApp.defaultApp()?.options.clientID
GIDSignIn.sharedInstance().delegate = self
return true
}
openURL url: NSURL, options: [String: AnyObject]) -> Bool {
return GIDSignIn.sharedInstance().handleURL(url,
sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String,
annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
}
openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
var options: [String: AnyObject] = [UIApplicationOpenURLOptionsSourceApplicationKey: sourceApplication,
UIApplicationOpenURLOptionsAnnotationKey: annotation]
return GIDSignIn.sharedInstance().handleURL(url,
sourceApplication: sourceApplication,
annotation: annotation)
}
// func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// // Override point for customization after application launch.
// let splitViewController = self.window!.rootViewController as! UISplitViewController
// let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as! UINavigationController
// navigationController.topViewController!.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem
// splitViewController.delegate = self
// return true
// }
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
// MARK: - Split view
func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController:UIViewController, onto primaryViewController:UIViewController) -> Bool {
guard let secondaryAsNavController = secondaryViewController as? UINavigationController else { return false }
guard let topAsDetailController = secondaryAsNavController.topViewController as? DetailViewController else { return false }
if topAsDetailController.detailItem == nil {
// Return true to indicate that we have handled the collapse by doing nothing; the secondary controller will be discarded.
return true
}
return false
}
}
Run Code Online (Sandbox Code Playgroud)
从您的代码中可以清楚地看出您当前正在运行Swift 3.0但您的某些方法仍然是Swift 2。对于Swift 3.0,新的委托方法是
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!)
{
if error != nil
{
print("Google Sign In Error")
}
else
{
// Do stuff
}
}
Run Code Online (Sandbox Code Playgroud)
openURL,didFinishLaunchingWithOptions并且在Swift 3.0didDisconnectWithUser中也发生了变化。我建议您重新实施它们。
| 归档时间: |
|
| 查看次数: |
2915 次 |
| 最近记录: |