Comments (8)
Have you made any headway on this? I'd like to know I'm having issues with my project right now too
from parselivequery-ios-osx.
It doesn't seem you retain the subscription
from parselivequery-ios-osx.
@flovilmart How do you retain the subscription? I also have a code like this
Here's my model
class Post: PFObject, PFSubclassing {
@NSManaged var caption: String?
@NSManaged var type: String?
class func parseClassName() -> String {
return "Post"
}
convenience init(_ caption: String) {
self.init()
self.caption = caption
self.type = "normal"
}
}
Here's my listener code
let PFLiveQuery: ParseLiveQuery.Client = ParseLiveQuery.Client()
let postQuery = Post.query()!
postQuery.whereKey("type", equalTo: "normal")
// This is just to test if I'm querying anything in the background
postQuery.findObjectsInBackground { (ob, er) in
print(ob, er) // this logs
}
let subscription = PFLiveQuery.subscribe(postQuery)
.handle({ Event.created($0)}, { (query, object) in
print("PLEASE LOG PLEASE PLEASE LOG") // this doesn't log
})
.handleError({ (query, error) in
print("error happened", query, error) // this doesn't log
})
.handleSubscribe({ (query) in
print("subscribe happened", query) // this doesn't log
})
.handleUnsubscribe({ (query) in
print("unsubscribe happened", query) // this doesn't log
})
.handleEvent({ (query, event) in
switch event {
case .created(let object):
print(object as Any) // this doesn't log
case .deleted(let object):
print(object as Any) // this doesn't log
case .entered(let object):
print(object as Any) // this doesn't log
case .left(let object):
print(object as Any) // this doesn't log
case .updated(let object):
print(object as Any) // this doesn't log
}
})
print(subscription) // this logs
Here is what I'm trying to send
let post = Post(textField.text!)
post.saveInBackground { (success, error) in
if let error = error {
print("not sent", error) // this logs if there's an error
} else {
print("sent") // this logs
}
}
I don't know why it doesn't work too
from parselivequery-ios-osx.
Just make it a property in the class that holds the listener code instead of just keeping it a local variable
from parselivequery-ios-osx.
Will that work?
from parselivequery-ios-osx.
Update: I did it like this
class ViewController: UIViewController {
var btnSend: UIButton?
var textField: UITextField?
var subscriber: ParseLiveQuery.Client!
override func viewDidLoad() {
super.viewDidLoad()
subscriber = ParseLiveQuery.Client()
btnSend = view.viewWithTag(12) as! UIButton
UITextField = view.viewWithTag(13) as! UITextField
btnSend.addTarget(self, action: #selector(self.sendClicked(sender:)), for: .touchUpInside)
startSocketListener()
}
func startSocketListener() {
print("startSocketListener")
Post.registerSubclass()
let postQuery = Post.query()!
postQuery.whereKey("type", equalTo: "normal")
// postQuery.findObjectsInBackground { (ob, er) in
// print(ob, er)
// }
let subscription = subscriber.subscribe(postQuery)
.handle({ Event.created($0)}, { (query, object) in
print("PLEASE LOG PLEASE PLEASE LOG")
})
.handleError({ (query, error) in
print("error happened", query, error)
})
.handleSubscribe({ (query) in
print("subscribe happened", query)
})
.handleUnsubscribe({ (query) in
print("unsubscribe happened", query)
})
.handleEvent({ (query, event) in
switch event {
case .created(let object):
print(object as Any)
case .deleted(let object):
print(object as Any)
case .entered(let object):
print(object as Any)
case .left(let object):
print(object as Any)
case .updated(let object):
print(object as Any)
}
})
print(subscription)
}
@IBAction func tryClicked(_ sender: Any) {
startSocketListener()
}
func sendClicked(sender: UIButton) {
guard !textField.text!.isEmpty else {
return
}
let post = Post(textField.text!)
post.saveInBackground { (success, error) in
if let error = error {
print("not sent", error)
} else {
print("sent")
self.textField.text = ""
}
}
}
}
Still does not work
from parselivequery-ios-osx.
Update: I am 100% sure that my ParseLiveQuery works since my JS code works seamlessly.
var Parse = require('parse/node');
Parse.initialize("....", ".....", "......");
Parse.serverURL = '.....';
var Post = Parse.Object.extend('Post');
var query = new Parse.Query(Post);
query.equalTo('type', 'normal');
var subscription = query.subscribe();
subscription.on('create', function (message) {
console.log('Message created with text: ' + message.get('caption'));
});
subscription.on('update', function (message) {
console.log('Message updated with text: ' + message.get('caption'));
});
subscription.on('delete', function (message) {
console.log('Message deleted with text: ' + message.get('caption'));
subscription.unsubscribe();
});
console.log('Running');
This works perfectly.
from parselivequery-ios-osx.
Okay I have now made it work. I basically misinterpreted you when you said Just make it a property in the class that holds the listener code instead of just keeping it a local variable
cause I only made ParseLiveQuery.Client
as the property instead of the Subscription<PFObject>
It works now
from parselivequery-ios-osx.
Related Issues (20)
- Subscription handler failing on array of subscriptions HOT 4
- Change query for subscription? HOT 1
- What about using Apple's Network framework instead of Starscream? HOT 3
- Subscription for PFUser current user - Swift
- ParseLiveQuery: WebSocket did disconnect with error: nil HOT 5
- Issue with nested PFQuery in a OR query HOT 1
- Xcode 12 beta 6 / iOS 14 incompatibility HOT 10
- Receiver type 'PFLiveQueryEvent' for instance message is a forward declaration (Xcode 12 Beta 6 / Objective-C project) HOT 6
- Could not build Objective-C module 'ParseLiveQuery' HOT 4
- ParseLiveQuery v2.7.2 not pushed into Cocoapods HOT 1
- Please update Starscream dependency up to '~> 3.1.1' how it was before in your `v2.7.0` release.
- Podfile update needed HOT 2
- LiveQuery interrupted by external operation on the table it monitors on HOT 3
- LiveQuery doesn't repsond to networking changes HOT 5
- Add release automation HOT 1
- Please add SPM Support HOT 5
- ParseLiveQuery: Received ping but we don't handle it... HOT 7
- ParseLiveQuery: Received ping but we don't handle it... HOT 1
- Merge as module with main SDK HOT 8
- Emitted Events from WebSocket pings not forwarded to Subscription Handler HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parselivequery-ios-osx.