GIDSignIn.sharedInstance : sharedInstance not a function? - swift

In this code, when I type GIDSignIn.sharedInstance, for some reason sharedInstance is not a function, which means I can't acces clientID. I cannot find a solution for this anywhere.
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
}

In latest version of GoogleSignIn SDK. Removed this method.
Now in new follow this link or below code.
https://developers.google.com/identity/sign-in/ios/sign-in
#IBAction func clkLoginWithGmail(_ sender: UIButton) {
let signInConfig = GIDConfiguration.init(clientID: "clientID-XYZ")
GIDSignIn.sharedInstance.signIn(with: signInConfig, presenting: self) { user, error in
}
}

Related

Thread 1: "-[UITableViewController loadView] loaded the \"Bf3-ih-lsC-view-YnG-aC-da7\" nib but didn't get a UITableView."

import UIKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Model.shared.loadXMLFile(date: nil)
Model.shared.parseXML()
return true
}
// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
}
}
When you create a UITableViewController in your storyboard, its main view must be a UITableView. This error often happens when some other controller type is changed to a UITableViewController but with its old main view still in place.

Setter for 'statusBarStyle' was deprecated in iOS 9.0: Use -[UIViewController preferredStatusBarStyle]

How do I rewrite the code snippet according to this;
Setter for 'statusBarStyle' was deprecated in iOS 9.0: Use -[UIViewController preferredStatusBarStyle]
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions:
[UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
UIApplication.shared.statusBarStyle = .lightContent
return true
}
This is the new method for status bar styles
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}

ElementQuiz app- thread 1: breakpoint 1.4

I'm trying to build an ElementQuiz app using the book "App Development with Swift" (from iBooks). When I run the app, it crashes and goes to the AppDelegate page, and shows a green line that says "thread 1: breakpoint 1.4".
Here's the ViewController.swift:
// ViewController.swift
// ElementQuiz
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
updateElement()
}
#IBOutlet weak var image view: UIImageView!
#IBOutlet weak var answerLabel: UILabel!
#IBAction func showAnswer(_sender: Any) {
answerLabel.text = elementList[currentElementIndex]
}
#IBAction func gotoNextElement(_sender: Any) {
currentElementIndex += 1
if currentElementIndex >= elementList.count {
currentElementIndex = 0
}
updateElement()
}
let elementList = ["Carbon", "Gold", "Chlorine", "Sodium"]
var currentElementIndex = 0
func updateElement() {
answerLabel.text = "?"
let elementName = elementList[currentElementIndex]
let image = UIImage(named: elementName)
imageView.image = image
}
}
And here's the AppDelegate.swift:
//AppDelegate.swift
//ElementQuiz
import UIKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
// This is the line with the "signal SIGABRT" error.
var window: UIWindow?
func application(_application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//Override point for customization after application launch.
return true
}
}
That was my code.
Delete all connections here (see the picture). Only you have this connection.

Facebook login + Firebase + Xcode 8 & Swift 3. ERROR

Xcode keeps complaining about an ambigous reference I've made in the AppDelegate. I'm trying to integrate Facebook Login with Firebase in my Xcode project using this tutorial.
Error:
Ambiguous reference to member
'application(_:didFinishLaunchingWithOptions:)'
Code:
import UIKit
import CoreData
import Firebase
import FBSDKLoginKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FIRApp.configure()
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
private func application(_ app: UIApplication, open url: URL, options: UIApplicationOpenURLOptionsKey) -> Bool {
var handled = FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey], annotation: options[UIApplicationOpenURLOptionsAnnotationKey]) // Error happens here
// Add any custom logic here.
return handled
}
I'm not sure what what this error means (still new to iOS programming). I've highlighted where it happens in the code with a comment.
import UIKit
import Firebase
import CoreData
import FBSDKCoreKit
import FBSDKLoginKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FIRApp.configure()
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
func application(_ application: UIApplication, open url: URL, _: NSURL, sourceApplication: String, annotation: AnyObject) -> Bool {
let handled: Bool = FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
return handled
}

How Return to the App Login screen when resuming an app from background?

I have an app with multiple views. I would like the app to present to login screen whenever the app is resumed from background. How can I do this?
I was trying to modify the AppDelegate.swift but I didn't know which code should I add to switch the view.
(Code below doesn't work)
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.
let vc: AnyObject? = self.storyboard?.instantiateViewControllerWithIdentifier("loginSID")
self.presentViewController(vc as UIViewController, animated: true, completion: nil)
}
Here is some code from one of my own applications that does this very thing. It shows an authentication screen any time the user switches out and comes back. Obviously not all of it may be relevant to you, but I'll bet a lot of it is. If you'd like I can share more and show how I implemented the AuthViewController and such as well.
import UIKit
import SQLite
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate
{
var window: UIWindow?
var database: Database
var authenticated: Bool = false
var password: String = ""
override init()
{
let path = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first as String
database = Database("\(path)/db.sqlite3")
}
class func shared() -> AppDelegate!
{
return UIApplication.sharedApplication().delegate as AppDelegate
}
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
return true
}
func applicationWillResignActive(application: UIApplication)
{
authenticated = false
}
func applicationDidEnterBackground(application: UIApplication) {}
func applicationWillEnterForeground(application: UIApplication)
{
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let rootController = storyboard.instantiateViewControllerWithIdentifier("authView") as AuthController
self.window?.rootViewController?.dismissViewControllerAnimated(false, completion: {
if self.window != nil
{
self.window!.rootViewController = rootController
}
})
}
func applicationDidBecomeActive(application: UIApplication) {}
func applicationWillTerminate(application: UIApplication)
{
authenticated = false
}
}