Comments (13)
Always try to connect, and through an error "Swift ddp connection closed with error 1000, clean true "
and in loop try to connect -> again fail->again subscription fail....
from swiftddp.
Can you share the code you're trying to run to connect and subscribe?
from swiftddp.
I have a code given below. Once error come "Swift ddp connection closed with error 1000, clean true " it tries to reconnect , So calls Meteor.connect but fail to subscribe and shows "already subscribed" and same cycle repeats. Also I don't get any updates from server. And also I am not getting any 'pong' messages, although i am having good network connection, still it gives me error periodically.
. I am new at swift so it may be my implementation mistake. Thanking you in anticipation.
`func connectToServer(collectionId: String) -> Bool {
Meteor.connect(Config.URL) {
self.subscribe(collectionId)
}
return true
}
private func subscribe(collectionId : String) {
Meteor.subscribe("collection name" , params: [collectionId]) {
self.collectionId = collectionId
self.collectionSubscriptionIsReady("connected")
}
}
private func collectionSubscriptionIsReady(result : String) {
print("Subscribed to collectoin ");
delagate?.connected(result)
}`
from swiftddp.
I don't see anything obviously wrong, but you're wrapping all of the Meteor methods in your own class, and I wonder how you're using that class.
- First, have you enabled logging?
swift Meteor.client.logLevel = .Debug
before you connect. That would enable you to see pongs, as well as other debug messages. - Where are you making your connection and subscription? You should only do this once in the app, and doing this in your AppDelegate is a good place to do it.
from swiftddp.
I have one app in which I need to subscribe to the one collection with specific ID as like mahadevTW's code.
If user want to open another data set in same collection with different ID, So we need to subscribe to the another Data Set from the same collection. So I need to unsubscribe and again resubscribe to the same collection with new ID.
Once reconnection is done it shows "Swift ddp connection closed with error 1000, clean true " and it will again subscribe and the cycle continues.
Due to different ID I need to call subscribe multiple times , which leads to previous error "connection closed"
My Server side code of publish is as follows :
Meteor.publish('collection', function (id) { return Collecion.find({$or:[{_id:id},{rootId:id}]}); });
And subscribe code is similar to MahadevTW.
So Is their be any appropriate way to resubscribe to the same collection with different parameters.
from swiftddp.
Thanks @SwapnilBGaikwad and @mahadevTW . I haven't encountered this issue before. I think there's an issue here, but it's tough to say what the issue is without being able to run the code. Would it be possible for one or both of you create a github repo with code that reproduces this issue?
from swiftddp.
I have created the repo on git hub which will shows the above connection closed error.
Here is the link of git hub repo.
https://github.com/SwapnilBGaikwad/SampleSwiftDDPCode.git
I have connected to the meteor site called http://www.mindit.xyz/create/zxg6nK4gdvNnL9yof
So please tell me proper way to deal with such situation in which I need to
subscribe to the collection with the same collection name but with different collection id.
from swiftddp.
I see now what you are doing.
Please see the todos example. It illustrates exactly what you are trying to do.
The short answer is: handle your subscription when you instantiate your view controller. Unsubscribe to the subscription when the view controller will disappear. viewWillDisappear is a good place to do this, as shown in the example.
Second, and importantly, you should only instantiate Meteor once, and this should probably be done in your app delegate. Again, see the example. You are trying to reconnect each time the user moves to MapTableViewController via your MeteorTracker class that wraps Meteor. This is wrong. So, one connection per app session.
I would get rid of the MeteorTracker class. Unless you instantiate MeteorTracker in AppDelegate, and remove the subscription logic from it, you really can't handle the subscriptions correctly. And if you do that, it's not doing much as a wrapper.
Finally, I ran your code for about 15 minutes, in several sessions and didn't get the "Swift ddp connection closed with error 1000, clean true ."
from swiftddp.
Thank you for your suggest I have implemented in my app and seems to be working fine.
But now I need to open my app from using custom URL scheme.
So when I opened for first time and subscribed and pressed home then try to open the app with new subscription parameter (id) passed in URL. So it says already subscribed and new subscription fails as expected.
In this condition , is their be any way to reset the things that are already subscribed when entered in AppDelegate method :
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool
from swiftddp.
I'm not sure I understand what you're trying to do. The way to reset a subscription is to unsubscribe from the publication.
from swiftddp.
If I opened app and subscribed with specific subscription parameter (id).
Now my app is connected and subscribed state.
In my app I am unsubscribing the collection in viewWillDisappear.
If subscription is done app and user then open app using URL scheme
e.g. myapp://id
then it simple say already subscribed as expected.
So I need to know in such a condition how to unsubscribe to collection.
If I unsubscribe when app goes in background then user will not get updates when user open the app present in background.
from swiftddp.
In this instance, I think the appropriate action is to unsubscribe and then resubscribe. Unsubscribe from your publications when the app will enter the background, and resubscribe when when the app becomes active again.
from swiftddp.
Your suggestion really helped me to resolve all of the error.
Thanks for your support.
👍
from swiftddp.
Related Issues (20)
- Keep sending request to server HOT 3
- subscribe observer
- Duplication HOT 1
- outdated CryptoSwift dependency HOT 4
- How to get info user?
- make custom id
- Swift 4 errors HOT 7
- Not able to compile on xcode9.4 with swift 4.1 HOT 1
- [Question] How can I use SwiftDDP in a command line tool? HOT 1
- Cocoapods version of the podspec file IS NOT up to date with the current version on GitHub HOT 2
- Unsupported version requirements in SwiftDDP.podspec HOT 4
- Xcode10/swift4 support HOT 1
- Unencrypted connection (ws://) throws 'SSLHandshake failed' HOT 1
- Unable to build after adding pod for Swift DDP in podfile for Xcode 10.1 and Swift 4.2.
- login meteor server with native facebook sdk in iOS ? HOT 1
- Doesn't build with new xcode HOT 2
- How to receive subscription with message and error log
- Expired Meteor login tokens are not being handled correctly HOT 1
- Ambiguous us of 'init(callback:)' HOT 4
- how To Access Direct Local database. without Creating Collections
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 swiftddp.