parsing云 – LiveQueries – iOS客户端不起作用
我正在尝试使用Parse LiveQueries。 我使用这个parsing“Bootstrap”:“ https://github.com/parse-community/parse-server ”,
我可以看到日志: info: Create new client: 1
,
但我只是没有得到在查询中的更新,虽然我订阅了它。 它甚至没有达到subscription.handle
的处理程序。
config.json
:
{ "appId": "", "masterKey": "", "appName": "", "cloud": "./cloud/main", "databaseURI": "", "publicServerURL": "", // Relevant "startLiveQueryServer": true, "liveQuery": { "classNames": ["Channel"] }, }
AppDelegate.swift
:
// Initialize Parse. let configuration = ParseClientConfiguration { $0.applicationId = self.PARSE_APP_ID $0.server = self.PARSE_SERVER } Parse.initialize(with: configuration) AppDelegate.liveQueryClient = ParseLiveQuery.Client()
The Subscription Code
(iOS Swift):
public static func listenSubscribedChannels(handler: @escaping (_ channel: Channel) -> Void) { var subscription: Subscription<PFObject>? let query: PFQuery<PFObject> = PFQuery(className: "Channel").whereKey("subscribers", containedIn: [PFUser.current()!.objectId]) subscription = AppDelegate.liveQueryClient!.subscribe(query).handle(Event.updated) { _, channel in handler(channel) } }
这个代码的问题是,你正在把这个代码var subscription: Subscription<PFObject>?
里面的function。
该对象必须能够保留它的内存地址以便接收事件。
例如。
class SomeClass { var objects: [PFObject] = [] var subscription: Subscription<PFObject>? var subscriber: ParseLiveQuery.Client! let query = PFQuery(className: "Locations") func startListener() { // initialize the client subscriber = ParseLiveQuery.Client() // initialize subscriber and start subscription subscription = subscriber.subscribe(conversationQuery) // handle the event listenrs. _ = subscription?.handleEvent({ (_, event) in switch event { case .created(let object): self.objects.append(object) // do stuff default: break // do other stuff or do nothing } }) } }
正如你从这段代码中看到的那样,我已经把variables放在了函数定义之外,以保持Subscription
的内存地址。
您必须在查询之前注册您的课程,如:
Channel.registerSubclass()
- 初始加载时导航控制器后面的UITableViewController中的UITableView
- 如何以迷人的屏幕forms向用户提供应用更新?
- 如何在纵向模式下lockingviewController
- PFObject不反映“parsing数据浏览器”中的“成功”保存的更改
- kCAFilterNearest maginifcationfilter(UIImageView)
- 如何使用Swift,iOS 7设置rootViewController
- 如何设置UILabel for iOS应用程序的左上alignment方式?
- 为什么我不能在我的iOS应用程序中添加本地化?
- phonegap 2.2方向更改不调整应用程序