При взятии данных из firebase и передаче их на новый Storyboard , данные прогружаются позже чем новый storyboard
Проблема в том что storyboard раньше грузится чем я передаю данные пытался через.GCD но не вышло. Плюс словил баг непонятный с firebase , отправил код знакомоу , при запуске и регестрации пользователя данные на сервер не отправляются , но в туже секунду я отправлял данные на сервер, в чем может быть проблема
LoginViewController - где проходит авторизация
@IBAction func didTapLoginButton(_ sender: UIButton) {
Auth.auth().signIn(withEmail: self.emailTextField.text!, password: self.passwordTextField.text!) {(result,error) in
if error != nil{
print("ПОЛЬЗОВАТЕЛЬ НЕ НАЙДЕТ !")
}else{
print("Авторизация прошла успешно")
let storyboard = UIStoryboard(name: "Main", bundle: nil)
guard let userID = Auth.auth().currentUser?.uid else { return }
print("------------------USER-ID-----------------")
print("USER ID \(userID)")
print("------------------USER-ID-----------------")
var userName = userID
APIManager.shared.getPost(collection: "users", docName: "\(userName)", completion: {doc in
guard doc != nil else{return}
var name = doc?.name
var email = doc?.email
print("-----------------------------------------------------------------------")
print("User NAME: \(name)")
guard let userPageViewController = storyboard.instantiateViewController(identifier:"UserPageViewController" ) as? UserPageViewController else {return}
userPageViewController.getUserName = name
print("Data transit")
}
)}
}
}
UserPageController - Куда данные должны перейти
import UIKit
class UserPageViewController: UIViewController {
@IBOutlet private weak var userAvatarIg: UIImageView!
@IBOutlet private weak var userNameLB:UILabel!
public var getUserName:String!
public var dateForLabel:String!
override func viewDidLoad() {
super.viewDidLoad()
userAvatarIg.layer.cornerRadius = userAvatarIg.frame.size.width/2
userAvatarIg.clipsToBounds = true
print("_----------------------------------------")
print("\(userNameLB)")
userNameLB.text = getUserName
// Do any additional setup after loading the view.
}
}
APIManager - Где хранится логика взятия данных
class APIManager {
static let shared = APIManager()
// MARK: - Config
private func configFB()->Firestore{
var db:Firestore!
let setting = FirestoreSettings()
Firestore.firestore().settings = setting
db = Firestore.firestore()
return db
}
// MARK: - Get info from db
func getPost(collection:String, docName:String, completion:@escaping(Document?)-> Void){
let db = configFB()
db.collection(collection).document(docName).getDocument { (document, error) in
guard error == nil else {completion(nil); return }
let doc = Document(name: document?.get("name") as! String, email: document?.get("email") as! String)
completion(doc)
}
}
ТЕРМИНАЛ :
2021-01-14 00:59:24.176895+0300 Client_Vk[41888:2141050] 7.3.0 - [Firebase/Analytics][I-ACS023007] Analytics v.7.3.0 started
2021-01-14 00:59:24.177109+0300 Client_Vk[41888:2141050] 7.3.0 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see ----------)
2021-01-14 00:59:24.531536+0300 Client_Vk[41888:2141093] 7.3.0 - [Firebase/Analytics][I-ACS800023] No pending snapshot to activate. SDK name: app_measurement
2021-01-14 00:59:24.775996+0300 Client_Vk[41888:2141051] 7.3.0 - [Firebase/Analytics][I-ACS023012] Analytics collection enabled
2021-01-14 00:59:24.776981+0300 Client_Vk[41888:2141051] 7.3.0 - [Firebase/Analytics][I-ACS023220] Analytics screen reporting is enabled. Call +[FIRAnalytics logEventWithName:FIREventScreenView parameters:] to log a screen view event. To disable automatic screen reporting, set the flag FirebaseAutomaticScreenReportingEnabled to NO (boolean) in the Info.plist
2021-01-14 00:59:36.945828+0300 Client_Vk[41888:2141051] [] nw_protocol_get_quic_image_block_invoke dlopen libquic failed
ПОЛЬЗОВАТЕЛЬ НЕ НАЙДЕТ !
ПОЛЬЗОВАТЕЛЬ НЕ НАЙДЕТ !
ПОЛЬЗОВАТЕЛЬ НЕ НАЙДЕТ !
2021-01-14 01:00:08.249113+0300 Client_Vk[41888:2139887] [Storyboard] Unknown class _TtC9Client_Vk25GroupsTableViewController in Interface Builder file.
_----------------------------------------
Optional(<UILabel: 0x7faca6f67a10; frame = (120 64; 86 21); text = 'User Name'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x6000020dca00>>)
----------VIEW-WILL-LAYOUT-SUBVIEWS----------
nil
----------VIEW-WILL-LAYOUT-SUBVIEWS----------
2021-01-14 01:00:08.373820+0300 Client_Vk[41888:2139887] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x6000020d2120 UIButton:0x7faca6d57550'\U0414\U0420\U0423\U0417\U042c\U042f'.centerY == UILabel:0x7faca6d572e0.centerY (active)>",
"<NSLayoutConstraint:0x6000020d21c0 V:|-(5)-[UIButton:0x7faca6d57550'\U0414\U0420\U0423\U0417\U042c\U042f'] (active, names: '|':UIView:0x7faca6f5b260 )>",
"<NSLayoutConstraint:0x6000020d2030 V:[UIButton:0x7faca6d57550'\U0414\U0420\U0423\U0417\U042c\U042f']-(4)-[UICollectionView:0x7faca80e1400] (active)>",
"<NSLayoutConstraint:0x6000020d1ef0 V:[UILabel:0x7faca6d572e0]-(9)-[UICollectionView:0x7faca80e1400] (active)>",
"<NSLayoutConstraint:0x6000020d1f40 V:|-(9)-[UILabel:0x7faca6d572e0] (active, names: '|':UIView:0x7faca6f5b260 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000020d1ef0 V:[UILabel:0x7faca6d572e0]-(9)-[UICollectionView:0x7faca80e1400] (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
----------VIEW-WILL-LAYOUT-SUBVIEWS----------
Optional(<UILabel: 0x7faca6f67a10; frame = (120 64; 86 21); opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x6000020dca00>>)
----------VIEW-WILL-LAYOUT-SUBVIEWS----------
Document successfully written!
Авторизация прошла успешно
------------------USER-ID-----------------
USER ID HSxXdlAkWjVyFCbJ1vf10rt3qHj1
------------------USER-ID-----------------
-----------------------------------------------------------------------
User NAME: Optional("anastas")
Data transit
2021-01-14 01:03:07.794819+0300 Client_Vk[41888:2145339] [ServicesDaemonManager] interruptionHandler is called. -[FontServicesDaemonManager connection]_block_invoke
Ответы (1 шт):
У Вас в коде нет строчки, где вы презентуете свой сториборд, значит, вы презентуете его где-то в другом месте (например, через segue), а в коде присваиваете проперти getUserName другому экземпляру сториборда, который, в свою очередь, никак не показываете. Соответственно, уберите предыдущую презентацию сторибода и сделайте present(userPageViewController, ...) после userPageViewController.getUserName = name. Тогда будет показан нужный сториборд с установленным значением getUserName.