小编Rai*_*lil的帖子

admin.firestore(...).document 不是导出函数

我正在运行一个由 firebase 实时数据库更改和更新 FireStore 触发的云函数。但是,虽然函数触发,但函数无法访问 Firestore。

exports.reveal = functions.database.ref('/reveals/{postIDthatWasRevealed}/revealed').onUpdate((change, context) => {
const revealedValue = change.after.val()

if (revealedValue === true) {
   var updates = {}
   const postID = context.params.postIDthatWasRevealed
   return admin.firestore().document('/posters/' + postID).get().then(querySnapshot => {
Run Code Online (Sandbox Code Playgroud)

此时,控制台日志指出TypeError:admin.firestore(...).document is not a function at..我已经尝试过这个答案:尝试过答案但问题仍然存在。这是否与我在 firebase 云功能内部访问 firestore 的事实有关?我的云功能是否没有正确更新?

编辑(包括初始化代码)

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
Run Code Online (Sandbox Code Playgroud)

此外,我尝试通过将其更改为来调试该功能:

if (revealedValue === true) {
   var updates = {}
   const postID = context.params.postIDthatWasRevealed

   return admin.firestore()
Run Code Online (Sandbox Code Playgroud)

现在,当我触发该函数时,我得到Function execution took 811 …

firebase google-cloud-firestore

6
推荐指数
2
解决办法
4346
查看次数

禁用相机视图生长动画

目前,我有一个 vie 控制器,它以模态方式呈现一个包含相机的视图控制器。但是,每当我转换时,预览层都会有一个动画,因此它会从左上角循环生长以填充屏幕的其余部分。我尝试禁用 CALayer 隐式动画但没有成功。这是视图出现时的代码。

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    previewLayer?.frame = self.view.frame
}

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    capturedImageView.center = self.view.center
    captureSession = AVCaptureSession()
    if usingFrontCamera == true {
    captureSession?.sessionPreset = AVCaptureSession.Preset.hd1920x1080
    }
    else {
    captureSession?.sessionPreset = AVCaptureSession.Preset.hd1280x720
    }

    captureDevice = AVCaptureDevice.default(for: AVMediaType.video)


    do {
        let input = try AVCaptureDeviceInput(device: captureDevice!)

        if (captureSession?.canAddInput(input) != nil) {
            captureSession?.addInput(input)

            stillImageOutput = AVCapturePhotoOutput()

            captureSession?.addOutput(stillImageOutput!)
            previewLayer = AVCaptureVideoPreviewLayer(session: captureSession!)
            previewLayer?.videoGravity = AVLayerVideoGravity.resizeAspect
            self.view.layer.addSublayer(previewLayer!)
            captureSession?.startRunning()


        }


    } catch {

    } …
Run Code Online (Sandbox Code Playgroud)

avcapturesession swift

3
推荐指数
1
解决办法
614
查看次数

按从最近到最远的顺序对 Firestore GeoHash 查询进行排序?

目前,我正在使用 GeoFirebase 库的部分内容以及 Firestore 来进行地理查询。当我设置帖子的 geohash 时,我是这样做的if let geoHash = GFGeoHash(location: location.coordinate).geoHashValue {

但是,为了使 geohash 查询不那么具体,我计划在查询时截断部分 geohash;目前,查询看起来与此类似

 var geoQuerySpecific = GFGeoHashQuery()
        let geoQueryHash =  GFGeoHashQuery.queries(forLocation: (lastLocation?.coordinate)!, radius: (30)) as! Set<GFGeoHashQuery>

        for query in geoQueryHash {
            geoQuerySpecific = query
            print("the key is this um \(geoQuerySpecific)")
        }
        print("the starting value is \(geoQuerySpecific.startValue)  and the end value is \(geoQuerySpecific.endValue)")
        let nearQuery = Firestore.firestore().collection("stuff").order(by: "g").whereField("g", isGreaterThanOrEqualTo: geoQuerySpecific.startValue).whereField("g", isLessThanOrEqualTo: geoQuerySpecific.endValue)
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,这将无法正常工作,因为 geoQueryHash 中有多个项目。当我在 firebase 中设置 geohash 时,我考虑过截断 geohash 的最后四位数字/字母,但是,这还不够具体。为了获得最接近的帖子,最好像我现在一样在数据库中设置 geoHashes,然后,在检索内容时,将起始值设置为查询的最具体的 geohash,然后将最终值设置为截断版本geohash,从获取最近的帖子开始并以最广泛的帖子结束?

我可以将 Firestore …

geolocation geohashing geofire google-cloud-firestore geofirestore

1
推荐指数
1
解决办法
2190
查看次数