I am getting an extra argument 'data' in call at the "addDocument(data: [".It was working fine all along,it was fine yesterday.I woke up today and run it and get this error.I am totally confused.
var db = Firestore.firestore()
func sendDataToDatabase(message: String){
let senderIDNumber = Auth.auth().currentUser?.uid
let timeStampString = String(Int(Date().timeIntervalSince1970))
db.collection("chats").addDocument(data: [
"message" : messageText.text!, "senderID" : senderIDNumber!, "receiverID" : receiverIDNumber!, "timestamp" : timeStampString!, "conversationsCounter" : conversationsCounterInt!
]) { err in
if let err = err {
print("Error writing document: \(err)")
} else {
print("Document successfully written!")
}
}
}
The answer is there is no problem with my code! It's firebase/firestore that is causing the problem.
I have been talking ,waiting for them to clean up the database for days but no one is solving the problem.
A simple debugging found that there the old data that has been deleted still remains in the firebase system.I emailed them but no one is solving my problem.
Related
I am trying to integrate WorldPay's "AccessCheckoutSDK" in my IOS Application using Swift by following
https://developer.worldpay.com/docs/access-worldpay/checkout/ios/card-only
while generating session it give me "Identity is invalid" error .
Here is the code i tried
func initializedSDK() -> AccessCheckoutClient? {
let accessCheckoutClient = try?
AccessCheckoutClientBuilder().accessBaseUrl(WORLDPAY_BASE_URL)
.merchantId(WORLDPAY_MERCHANT_ID)
.build()
return accessCheckoutClient
}
func createCardDetails(CardNumber : String , CardExpiry : String , CardCVC : String) -> CardDetails? {
let cardDetails = try? CardDetailsBuilder().pan(CardNumber)
.expiryDate(CardExpiry)
.cvc(CardCVC)
.build()
return cardDetails
}
func CreateSession(CardNumber : String , CardExpiry : String , CardCVC : String) {
guard let accessCheckoutClient = initializedSDK() else {
// not going here so accessCheckoutClient is initialized
return
}
guard let cardDetails = createCardDetails(CardNumber: CardNumber, CardExpiry: CardExpiry, CardCVC: CardCVC) else {
// Not going here , so card details are valid
return
}
try? accessCheckoutClient.generateSessions(cardDetails: cardDetails, sessionTypes: [SessionType.card , .cvc ]) { result in
DispatchQueue.main.async {
switch result {
case .success(let sessions):
// The session is returned in a Dictionary[SessionType:String]
//not going here
let cardSession = sessions[SessionType.card]
let cvcSession = sessions[SessionType.cvc]
case .failure(let error):
// The error returned is of type AccessCheckoutError
print("error \(error)")
// It is going here and prints this error below
}
}
}
}
I am getting this error
AccessCheckoutError(errorName: "bodyDoesNotMatchSchema", message: "bodyDoesNotMatchSchema : The json body provided does not match the expected schema", validationErrors: [AccessCheckoutSDK.AccessCheckoutError.AccessCheckoutValidationError(errorName: "fieldHasInvalidValue", message: "Identity is invalid", jsonPath: "$.identity")])
WORLDPAY_BASE_URL = "https://try.access.worldpay.com/"
Note : I am using worldPay in testMode and didn't activated live mode yet and made sure that WORLDPAY_MERCHANT_ID is correct.
After all the research on worldPay , i decide to mail to worldPay support, After a brief chat with them and after they went through my worldPay account, this was their final reply :
"Your account status, "basic", "free tier" does not permit you to have access to this endpoint."
I decided to answer my own question so that if anyone have the same problem while integrating WorldPay with test Account, This would help them. I still think WorldPay developer can handle this scenario better by returning this exact string straightforward in the api response instead of throwing a 500 server error.
I welcome other answers and information on this post as well. If you have something informative about worldPay integration to IOS, please feel free to comment or answer this question.
I am having an issue in the following swift code, using Parse-Server to save data online.
let xxDico = ["N8": "Eight", "N5": "Five"],
upLoadParseUnit = PFObject(className: "numberClass",
dictionary: xxDico)
print("xxDico : \(xxDico.count)")
upLoadParseUnit.saveInBackground {
(succeeded:Bool, error:Error?) in
if succeeded {
print("\(#function) succeeded!!")
} else {
if error?.localizedDescription == "NAME-USED" {
// A record previously existed with the same name.
print("\(#function) did not succeeded!!\nError: \(error?.localizedDescription)")
return
}
print("Error(1) in \(#function)\n" + (error?.localizedDescription)!)
}
}
And this is what I get in the debugging console:
xxDico : 2
Error(1) in executeUpLoad(_:)
The data couldn’t be read because it isn’t in the correct format.
This seems simple, but what am I doing wrong to get this error?
And what am I supposed to do?
when i run the following code i get this error.
['FIRESTORE INTERNAL ASSERTION FAILED: Invalid document reference. Document references must have an even number of segments, but User has 1']
func saveLabel(uid: String, label: String){
let userRef = db.collection("User").document(uid)
userRef.updateData(["label": label]) { (error) in
if error == nil {
print("updated")
}else{
print("not updated")
}
}
}
This error almost certainly means that uid is empty. You should log it to make sure.
Loading data from firestore while offline works as expected but a call to save never returns and there seems to be no timeout either.
This is a example save that works online but not offline:
func save() {
guard let uid = user?.uid else {
return
}
let db = Firestore.firestore()
var ref: DocumentReference? = nil
ref = db.collection("users").document(uid).collection("properties").addDocument(data: ["name": "test"]) { err in
if let err = err {
print("Error adding document: \(err)")
} else {
print("Document added with ID: \(ref!.documentID)")
}
}
}
Is there any known workaround?
UPDATE: Firebase support have confirmed it's a bug and that it "is now being worked on by our engineers". They are unable to give a timescale for when it will be fixed.
This is the expected behaviour - you should assume that the write will happen when the device comes back online. In my use cases, I've just continued with the normal flow and used my local data as my source of truth.
It's mentioned here: https://youtu.be/XrltP8bOHT0?t=680
I want to handle a friend request in my app written in Swift using Firebase. In my database, this means that the user sending the request needs to add the other user to their "sentRequests" dictionary, and the user receiving the request needs to add the user sending the requests to their "receivedRequests" dictionary. The problem is, if the user sending the request has a faulty connection and only does the first part, then it might cause issues. Either both writes should happen or none. What can I do to fix this? I included my code below for reference, but honestly if someone just sends me a good tutorial or answer here that would be just has helpful as correctly rewriting my code.
static func sendRequestFromCurrentUser(toUser userThatRequestWasSentTo : User, succeeded : #escaping (Bool)->Void ){
let ref = Database.database().reference().child("users").child(User.current.uid).child("sentRequests").child(userThatRequestWasSentTo.uid)
ref.setValue(userThatRequestWasSentTo.toDictionary(), withCompletionBlock: {(error, ref) in
if error == nil{
let currentUserRef = Database.database().reference().child("users").child(userThatRequestWasSentTo.uid).child("receivedRequests").child(User.current.uid)
currentUserRef.setValue(User.current.toDictionary(), withCompletionBlock: {(error, ref) in
if error == nil{
succeeded(true)
}
else{
succeeded(false)
}
})
}
else{
succeeded(false)
}
})
}
So I stole this from the Firebase blog and got it to match my code. The answer is fairly intuitive, I just hadn't considered it. Basically you just create a reference to the top level of your database and specify the paths you want to write to in the dictionary (so not by creating specific references with child()), and then just call updateChildValues().
static func sendRequestFromCurrentUser(toUser userThatRequestWasSentTo : User, succeeded : #escaping (Bool)->Void ){
let ref = Database.database().reference()
// Create the data we want to update
var updatedUserData : [String : Any] = [:]
updatedUserData["users/\(User.current.uid)/sentRequests/\(userThatRequestWasSentTo.uid)"] = userThatRequestWasSentTo.toDictionary()
updatedUserData["users/\(userThatRequestWasSentTo.uid)/receivedRequests/\(User.current.uid)"] = User.current.toDictionary()
// Do a deep-path update
ref.updateChildValues(updatedUserData, withCompletionBlock: { (error, ref) in
if let error = error {
print("Error updating data: \(error.localizedDescription)")
succeeded(false)
}
else{
succeeded(true)
}
})
}