我想知道如何将结果中的值传递给另一个视图控制器。
func showEmailAddress() -> Void{
//Adding user to firebase
let accessToken = FBSDKAccessToken.current()
guard let accessTokenString = accessToken?.tokenString else //This makes things a littie safer
{return}
let credentials = FacebookAuthProvider.credential(withAccessToken: accessTokenString)
Auth.auth().signIn(with: credentials) { (user, error) in
if error != nil {
print("something went wrong with out FB user: ", error ?? "")
return
}
print("Successfully logged in with our user: ", user ?? "")
UserDefaults.standard.set(user!.email!, forKey: "usersigned")
UserDefaults.standard.synchronize()
let delegate : AppDelegate = UIApplication.shared.delegate as! AppDelegate
delegate.rememberLogin()
}
//print("Succesfully loged in with facebook...")
FBSDKGraphRequest(graphPath: "/me", parameters: ["fields": "id, name, email"]).start { (connection, result, err) in
//print(123)
if err != nil{
print("Failed to start graph request:",err ?? "")
return
}
print("This is the results")
print(result ?? "")
let data:[String:AnyObject] = result as! [String : AnyObject]; print(data["name"]!); print(data["id"]!)
var username = data["name"]!
var userID = data["id"]!
//let number = "1234566"
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let DestViewController : menuViewController = segue.destination as! menuViewController
DestViewController.id = username
}
这些值仅存在于showEmailAddress()中。有没有办法从函数中提取它们以将用户名和用户ID发送到另一个VC?
最佳答案
使字符串在您的AppDelegate中像
var username = String()
var userid = String()
并在其中获取用户名和用户ID值的位置将其值发送到AppDelegate。使AppDelgate对象如下所示
let appDelegate = UIApplication.shared.delegate as! AppDelegate
将值传递给应用程序委托变量
self.appDelegate.username = "your Value"
self.appDelegate.userid = "your Value"
并按以下方式获取您想要的值
let string = appDelegate.username as! String
let string1 = appDelegate.userid as! String
传递的值
关于ios - 我想知道如何将结果中的值传递给另一个 View Controller 。,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44793658/