Comments (12)
Thanks for the good issue report.
I don't really know Objective-C well, but from your test code it looks like you're creating a local variable named socket and working with that. Once socket
goes out of scope it should be released.
Does this happen if you make the socket a member of the viewcontroller?
I usually have the socket be a member of the viewcontroller, and then do things like this in the viewDidLoad
https://github.com/nuclearace/socket.io-client-swift-example/blob/master/TicTacIOiOS/ViewController.swift#L28
from socket.io-client-swift.
Also, I should note I have no idea if Objective-C blocks are as powerful as Swift closures.
from socket.io-client-swift.
Thanks for a quick reply - I will look into it and report my findings. 😄
I know less swift than objective-c so I have my work cut out for me. 😄
from socket.io-client-swift.
Hm, actually I'm getting this too.
from socket.io-client-swift.
What's weird is this seems to work in Swift.
from socket.io-client-swift.
Also the code it's highlighting isn't the problem.
from socket.io-client-swift.
Swift 1.2 seems to get the line right, but I still can't figure out why it's happening
from socket.io-client-swift.
What's even weirder is that it doesn't seem to happen when I do something crazy like
SocketIOClient* gSocket;
void testSocketAck()
{
gSocket = [[SocketIOClient alloc] initWithSocketURL:@"localhost:8080" options:nil];
[gSocket on: @"connect" callback: ^(NSArray* data, void (^ack)(NSArray*)) {
NSLog(@"connected");
[gSocket emitWithAckObjc:@"ack" withItems:@[@1]](1, ^(NSArray* data) {
NSLog(@"Got ack");
NSLog(@"%@", data[0]);
[gSocket emitObjc:@"test" withItems:@[]];
});
}];
[gSocket connect];
}
from socket.io-client-swift.
Ugh, I found a really ugly workaround.
If you have a global variable that references your object, and then use that inside blocks it works.
from socket.io-client-swift.
@ahallora Actually I think I've found a solution
- (void) sendMessage {
__block int i;
[[self socket] emitWithAckObjc:@"ack" withItems:@[@1]](1, [^(NSArray* data) {
NSLog(@"Got ack");
[[self socket] emitObjc:@"test" withItems:@[]];
i = 1 + 1;
} copy]);
}
Can you confirm that sending the copy message to the block fixes it.
If that's the case, I'll update the readme
from socket.io-client-swift.
This is actually a problem with Swift-Objective-C compatibility. I worked out a small demo here
from socket.io-client-swift.
Awesome, it works! Thank you so much! 👍 😃
from socket.io-client-swift.
Related Issues (20)
- Socket.IO-Client-Swift version 16 Crash on iOS 16, built with Xcode 15 HOT 6
- Does the library support socks proxy?
- Reconnect Auth Behavior
- socket.emitWithAck(...)timingOut(...) timeout callback never called HOT 2
- LOG SocketManager: Tried connecting an already active socket
- Cannot connect to server, when android client can connect HOT 3
- Privacy Manifest HOT 3
- Potential Memory Management Issue with emitWithAck and timingOut(after:) HOT 1
- How can i use SocketIO without Rosetta on Apple Silicon
- Compiling for iOS 10.0, but module 'Starscream' has a minimum deployment target of iOS 12.0 HOT 1
- Socket didn't send or get any Ping Pong Events HOT 4
- Implement Connection State Recovery
- Starscream version (4.0.8) HOT 3
- Socket not connecting HOT 4
- Volatile events
- Compiling for iOS 11.0, but module 'Starscream' has a minimum deployment target of iOS 12.0 HOT 2
- Keep listening socket when user enters background HOT 2
- Compiling for iOS 11.0, but module 'Starscream' has a minimum deployment target of iOS 12.0 HOT 3
- emitWithAck returning No ACK HOT 10
- Why Starscream v4.0.8
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 socket.io-client-swift.