Ich habe für eine ganze Nacht und einen halben Tag kämpfen, bevor aufgegeben und um Hilfe bitten. Ich habe mehrere Threads hier auf Stackoverflow lesen, aber jede Lösung scheint zu funktionieren, aber das, obwohl die App Absturz beim StartImplementieren sowohl Facebook und Google SignIn API in Swift 3.0
2016-10-26 16:03:58.793 MotivaMe[3997:404331] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<MotivaMe.ViewController 0x7ff1a0407700> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key loginButtonFB.'
FIXED SEE BODEN FÜR DIE LÖSUNG
EDIT: Compiler sagt jetzt: „Die Umsetzung der Anwendung : openURL: sourceApplication: Anmerkung: nicht gefunden. Fügen Sie den Handler zu Ihrem App-Delegierten hinzu. " Insbesondere nach der Authentifizierung bleibe ich stecken und werde nicht zur App weitergeleitet
Dies ist das erste Mal, dass ich versuche, für iOS zu kodieren, also bin ich immer noch nicht so zuversichtlich mit CocoaTouch, das ich gerade studiere . Jede Hilfe ist dank geschätzt (eine Erklärung über das Update wirklich geschätzt werden würde, da ich nicht, was falsch bekommen, vielen Dank an alle)
Hier ist die AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
{
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
var configureError: NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError)")
GIDSignIn.sharedInstance().delegate = self
return true
}
func application(application: UIApplication, openURL url: NSURL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool
{
let googleDidHandle = GIDSignIn.sharedInstance().handle(
url as URL!,
sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String,
annotation: options[UIApplicationOpenURLOptionsKey.annotation])
let facebookDidHandle = FBSDKApplicationDelegate.sharedInstance().application(
application,
open: url as URL!,
sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String,
annotation: options [UIApplicationOpenURLOptionsKey.annotation])
return googleDidHandle || facebookDidHandle
}
// The sign-in flow has finished and was successful if |error| is |nil|.
func sign(_ doLoginGoogle: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!)
{
if (error == nil)
{
// Perform any operations on signed in user here.
let userId = user.userID // For client-side use only!
let idToken = user.authentication.idToken // Safe to send to the server
let fullName = user.profile.name
let givenName = user.profile.givenName
let familyName = user.profile.familyName
let email = user.profile.email
// ...
print(userId,idToken,fullName,givenName,familyName,email)
}
else
{
print("\(error.localizedDescription)")
}
}
Und hier ist die ViewController.swift
override func viewDidLoad() {
super.viewDidLoad()
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().signInSilently()
}
@IBOutlet weak var doLoginFacebook: FBSDKLoginButton!
@IBOutlet weak var doLoginGoogle: GIDSignInButton!
func loginButtonDidLogOut(_ doLoginFacebook: FBSDKLoginButton!)
{
print("Did log out of facebook")
}
func loginButton(_ doLoginFacebook: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!)
{
if error != nil
{
print(error)
return
}
else
{
if(FBSDKAccessToken.current() != nil) //useless check but want to get confident with the api
{
//TODO implement switching pages on login
print("Sucessfully logged into facebook!")
}
}
}
verwenden Sie Storyboards oder Nibs? – dirtydanee