SocketRocket connection is suspended in the background

I use SocketRocket , but I can not get it to send messages in the background. When I open the application again, it resumes the connection (without reconnecting), and all messages arrive immediately.

Here is my connection code:

- (void)_reconnect {
    _websocket.delegate = nil;
    [_websocket close];

    NSString *host = @"ws://localhost:3030/primus";

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:host]];
    [request setValue:[NSString stringWithFormat:@"<%@>", apiKey] forHTTPHeaderField:@"Authentication"];

    _websocket = [[SRWebSocket alloc] initWithURLRequest:request];
    [_websocket setDelegateOperationQueue:[NSOperationQueue new]];
    _websocket.delegate = self;

    [_websocket open];

    if (DEBUG) {
        NSLog(@"Using: %@", host);
    }
}

I also tried without

[_websocket setDelegateOperationQueue:[NSOperationQueue new]];

but nothing helps.

Do you know what is going on?

Thank!

+4
source share
2 answers

I ran into the same problem and I don't have the correct answer yet.

, Socket Rocket SRDelegate, ( ).

:

    [_webSocket setDelegateDispatchQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)];

, , . , , , .

, , WebSocket .

, : DidEnterBackground:

CLLocationManager* locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];

, WillEnterForeground:

[locationManger stopUpdatingLocation];

Ofc locationManager .

, ...

+1

, , . - . . . .

, , ( ).

0

Source: https://habr.com/ru/post/1531452/


All Articles