Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
Swift/Firebase: no se pueden enviar datos de solicitud en una función de nube de Firebase

Parece que no puedo enviar un identificador sobre un cuerpo de solicitud a Firebase desde una aplicación Swift iOS.

Mi código javascript funciona (lo probé en un generador de API):

 exports.numberOfVideos = functions.https.onRequest((request, response) => { var attributionID = request.body.data.attributionID || "No attributionID found."; functions.logger.info('[LOG]: request.body has a value of ' + JSON.stringify(request.body), {structuredData: true}); var db = admin.firestore(); db.collection("content").get().then(snapshot => { var total = 0; snapshot.forEach(doc => { if (doc.data().attributionID == attributionID) { total++; } // stuff = stuff.concat(newelement); }); response.send('{"data": {"attributionID": "' + attributionID + '", "numberOfContents": "' + total + '"}}'); return ""; }).catch(reason => { response.send(reason) }) });

Mi código Swift no puede ver para transmitir los datos:

 static func getContentCount(for obj: Object, completion: @escaping (_ count: Int?) -> Void) { let httpsCallable = functions.httpsCallable("numberOfVideos") // httpsCallable.setValue("application/json", forKey: "Content-Type") httpsCallable.call(["attributionID" : obj.id]) { result, error in if let error = error as NSError? { if error.domain == FunctionsErrorDomain { let code = FunctionsErrorCode(rawValue: error.code) let message = error.localizedDescription let details = error.userInfo[FunctionsErrorDetailsKey] print(error) } } if let response = result?.data as? [String: [String: Any]] { if let data = response["data"] { if let countAsAString = data["numberOfContents"] as? String { let count = Int(countAsAString) if count != nil { completion(count) } else { print("Data is valid but no count found: \(result?.data)") completion(nil) } } } } else { print("Data is invalid: \(result?.data)") completion(nil) } } }

Cuando funcionó desde un probador de API REST, aquí estaba el cuerpo:

 POST /numberOfVideos HTTP/1.1 Host: ***************** Content-Type: application/json Content-Length: 49 {"data":{"attributionID":"biNiaWVtmjUKoTQ1fTZu"}}

¡Cualquier ayuda sería apreciada!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Arreglado. Tuve que usar un NSDictionary, no un diccionario:

 NSDictionary(dictionary: ["attributionID" : obj.id])
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!