Reputation: 1
I'm facing an issue with NSURLSessionWebSocketDelegate in my iOS application. I've set up the websocket connection using NSURLSessionWebSocket and implemented the necessary delegate methods, but it seems that the delegate methods are not being called.
Despite setting up the delegates properly, these methods aren't triggered when expected. I've double-checked my code for any potential mistakes but haven't been able to identify the issue.
Could someone please guide me on potential reasons why the delegate methods might not be called for NSURLSessionWebSocket? Any suggestions or insights would be greatly appreciated.
Note: Websocket successfully connected
NSURLSessionWebSocketTask *webSocketTask;
NSURLRequest *immutableRequest = [mutableRequest copy];
NSURLSession *session = [NSURLSession sharedSession];
webSocketTask = [session webSocketTaskWithRequest:[mutableRequest copy]];
webSocketTask.delegate = self;
[webSocketTask resume];
@interface YourViewController () <NSURLWebSocketDelegate>
// ... other code ...
@end
@implementation YourViewController
#pragma mark - NSURLWebSocketDelegate
- (void)webSocket:(NSURLWebSocket *)webSocket didReceiveMessage:(id)message { // Handle received message }
- (void)webSocket:(NSURLWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean { // Handle websocket closure }
@end
Upvotes: 0
Views: 179