解析 LiveQuery 不订阅 - Android (Kotlin)
Parse LiveQuery Not Subscribing - Android (Kotlin)
我正在将我的 Android 应用程序从 Java 重写为 Kotlin。我正在使用 Parse LiveQuery on Android,但似乎无法使订阅正常工作。
我正在使用此代码启动 LiveQuery 但没有收到任何响应。我知道数据库中的 table 启用了 liveQuery。我还知道相同的订阅在该应用程序的 Java 版本中有效。
fun startListeningToNotifications() {
//Build Live Query Client
val parseLiveQueryClient = ParseLiveQueryClient.Factory.getClient()
//Build Query
var parseQuery = ParseQuery.getQuery<ParseObject>("Notifications")
parseQuery.whereEqualTo("toUser", ParseUser.getCurrentUser())
parseQuery.orderByAscending("createdAt")
parseQuery.findInBackground { objects, e ->
//Do something with notifications
}
//Build Live Query Listener
var subscriptionHandling: SubscriptionHandling<ParseObject> = parseLiveQueryClient.subscribe(parseQuery)
subscriptionHandling.handleSubscribe {
Toast.makeText(this, "SUBSCRIBED", Toast.LENGTH_LONG).show()
}
subscriptionHandling.handleEvents { query, event, `object` ->
fetchNotificationCount()
}
subscriptionHandling.handleError { query, exception ->
Toast.makeText(this, exception.message, Toast.LENGTH_LONG).show()
}
}
非常感谢任何帮助。几天来一直坚持这个问题,GitHub 问题跟踪器没有任何帮助,因为它要么已经过时,不能与 Kotlin 一起使用,要么只是一个不同的问题。
编辑
在此处附上调试器的图像,希望它能帮助其他人意识到我哪里出错了。
我已经解决了这个问题。指定服务器时URL,如果使用nginx服务器,必须指定端口否则会失败
我的解析配置如下所示:
Parse.initialize(
Parse.Configuration.Builder(context)
.applicationId("appId")
.clientKey("clientKey")
.server("https://yourdomain.com/database/parse")
.enableLocalDataStore()
.build()
)
正确的配置是:
Parse.initialize(
Parse.Configuration.Builder(context)
.applicationId("appId")
.clientKey("clientKey")
.server("https://yourdomain.com:1337/parse")
.enableLocalDataStore()
.build()
)
我正在将我的 Android 应用程序从 Java 重写为 Kotlin。我正在使用 Parse LiveQuery on Android,但似乎无法使订阅正常工作。
我正在使用此代码启动 LiveQuery 但没有收到任何响应。我知道数据库中的 table 启用了 liveQuery。我还知道相同的订阅在该应用程序的 Java 版本中有效。
fun startListeningToNotifications() {
//Build Live Query Client
val parseLiveQueryClient = ParseLiveQueryClient.Factory.getClient()
//Build Query
var parseQuery = ParseQuery.getQuery<ParseObject>("Notifications")
parseQuery.whereEqualTo("toUser", ParseUser.getCurrentUser())
parseQuery.orderByAscending("createdAt")
parseQuery.findInBackground { objects, e ->
//Do something with notifications
}
//Build Live Query Listener
var subscriptionHandling: SubscriptionHandling<ParseObject> = parseLiveQueryClient.subscribe(parseQuery)
subscriptionHandling.handleSubscribe {
Toast.makeText(this, "SUBSCRIBED", Toast.LENGTH_LONG).show()
}
subscriptionHandling.handleEvents { query, event, `object` ->
fetchNotificationCount()
}
subscriptionHandling.handleError { query, exception ->
Toast.makeText(this, exception.message, Toast.LENGTH_LONG).show()
}
}
非常感谢任何帮助。几天来一直坚持这个问题,GitHub 问题跟踪器没有任何帮助,因为它要么已经过时,不能与 Kotlin 一起使用,要么只是一个不同的问题。
编辑
在此处附上调试器的图像,希望它能帮助其他人意识到我哪里出错了。
我已经解决了这个问题。指定服务器时URL,如果使用nginx服务器,必须指定端口否则会失败
我的解析配置如下所示:
Parse.initialize(
Parse.Configuration.Builder(context)
.applicationId("appId")
.clientKey("clientKey")
.server("https://yourdomain.com/database/parse")
.enableLocalDataStore()
.build()
)
正确的配置是:
Parse.initialize(
Parse.Configuration.Builder(context)
.applicationId("appId")
.clientKey("clientKey")
.server("https://yourdomain.com:1337/parse")
.enableLocalDataStore()
.build()
)