swift - 使用 Swift 在 Parse Server 中触发

标签 swift triggers digital-ocean parse-cloud-code parse-server

最近,我的任务是使用 Swift 为 iOS 开发一个简单的聊天应用程序。因此,我已经准备好并运行了一个解析服务器!我只想知道如何使用触发器..

假设我打开了一个对话并且刚刚收到一条新消息。如果不经常检查新消息,我怎样才能得到它?我看到云代码可能是可行的方法,但如果是这样,是否实用?我的意思是,如果我有 5000 个用户并且他们一直在聊天,它会表现良好吗?

提前致谢!

最佳答案

您想使用 Parse LiveQuery组件。

  1. Add Live Query to your server's config :

    let api = new ParseServer({
      ...,
      liveQuery: {
        classNames: ['Test', 'TestAgain']
      }
    });
    
    // Initialize a LiveQuery server instance, app is the express app of your Parse Server
    let httpServer = require('http').createServer(app);
    httpServer.listen(port);
    var parseLiveQueryServer = ParseServer.createLiveQueryServer(httpServer);
    
  2. 将 Parse LiveQuery 库作为 pod 安装到您的项目 (pod 'ParseLiveQuery')。

  3. 订阅事件:

    let myQuery = Message.query()!.where("user", equalTo: PFUser.currentUser()!)
    let subscription: Subscription<Message> = myQuery.subscribe()
    
  4. 处理事件:

    subscription.handleEvent { query, event in
        // Handle event
        // This callback gets called every time an object is created, updated, deleted etc.
    }
    

关于swift - 使用 Swift 在 Parse Server 中触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39155674/

相关文章:

php - 将参数传递给postgresql中的触发函数

sql - 如何防止数据库触发器递归?

ubuntu - 自动启动解析服务器

linux - 为什么 Digital Ocean 上的主机名 FQDN 设置不正确?

运行 python 应用程序时 MySql 访问被拒绝 [Ubuntu 1604/NGINX/uWSGI]

ios - XC文本 : query for text in navigation bar

swift - 如何在 Swift 中使用 UISearchBar 和 NSFetchedResultsController 在 Core Data 上一次获取超过 1 个实体?

ios - 为什么使用 Swift 在 View 上执行某些操作时顶部导航栏会消失?

ios - 以编程方式创建物理约束区域,SpriteKit

sql - 使用 Merge 语句到触发器中