如何从class.swift文件

问题描述

在构建社交媒体应用程序时遇到问题。

我已经在我的LoginView上集成了一个“ Google登录按钮”(使用客户端ID,没有Firebase,GoogleSignIn Framework),并且在我登录gmail帐户后,它使我回到了相同的LoginView。

我想导航到SignUpView

enter image description here

,如果用户是第一次输入并且如果用户注册,则我想导航到HomeView。

我正在从 AppDelegate

中的功能获取用户数据
func sign(_ signIn: GIDSignIn!,didSignInFor user: GIDGoogleUser!,withError error: Error!) {
if let error = error {
if (error as NSError).code == GIDSignInErrorCode.hasNoAuthInKeychain.rawValue {
print("The user has not signed in before or they have since signed out.")
} else {
print("\(error.localizedDescription)")
}
return
}
getGoogleUserData(with: user)

现在,使用用户的idToken,我将数据发布到Graphql中的backendServer上,无论用户是否注册,我都将获取信息。

fileprivate func getAuth(with idToken : String) {
let params = ["id_token":"\((idToken))"]
print(params)
var request = URLRequest(url: URL(string: "confidential_URL_here")!)
request.httpMethod = "POST"
request.httpBody = try? JSONSerialization.data(withJSONObject: params,options: [])
request.addValue("application/json",forHTTPHeaderField: "Content-Type")
let session = URLSession.shared
let task = session.dataTask(with: request,completionHandler: { data,response,error -> Void in
if let safeData = data {
ParsingUserjson().parseJSON(with: safeData)
}
})
task.resume()
} 

这是我的parseJSON函数。我需要在此功能后执行此操作方面的帮助:-

class ParsingUserjson: ObservableObject {

func parseJSON(with loginjsON : Data) {

let decoder = JSONDecoder()

do{
let decodedUser = try decoder.decode(LoginData.self,from: loginjsON)

guard let shouldSignUp = decodedUser.user?.signin //This tells me whether the user is entering the app for first time or not

 else {
fatalError("Could not achieve signIn boolean data from loginjsON")
}

guard let accesstoken = decodedUser.accesstoken 

else {
fatalError("Could not get accesstoken from the loginjsON")
}


//I am checking if the user has created not created his username and is entering for first time

if decodedUser.user?.username == nil || shouldSignUp == true 
{


//**THIS IS THE PART I AM NEED HELP. WHAT TO DO AFTER THIS? HOW TO GO FROM HERE>**


}

else {
guard let userName = decodedUser.user?.username else { return }
}

}catch{
     fatalError("Could not decode loginjsON")
      }
  }
}

现在,有人可以帮助我如何将数据发送回LoginView并使用NavigationLink导航到SignUpView吗?还是有其他方法可以做到这一点。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)