I ended up using it on the Main thread and dropped a lot of other functionality on the main thread. Seems to be working fine so far.
Run Pusher on Background Thread iOS
-
23-06-2023 - |
Question
I am rendering html pages on main thread. Hence I cannot run Pusher on the same thread as the main thread as it keeps dropping messages.
Is there any way of running always running Pusher on a background thread in iOS?
I have tried Grand Central Dispatch but it does not work as after initialising, Pusher comes back on the main thread.
Thank you
this is what I have so far.
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
client = [PTPusher pusherWithKey:@"xxxxxxxx" delegate:self encrypted:NO];
client.reconnectAutomatically = YES;
client.reconnectDelay = 1; // defaults to 5 seconds
[client connect];
PTPusherChannel *channel = [client subscribeToChannelNamed:[NSString stringWithFormat:@"Company_%@", [Settings sharedSettings].company.companyID]];
[channel bindToEventNamed:@"ServicePrint" handleWithBlock:^(PTPusherEvent *channelEvent) {
NSLog(@"[pusher event] Received event %@", channelEvent);
//do some work here
}];
dispatch_async( dispatch_get_main_queue(), ^{
// Add code here to update the UI/send notifications based on the
// results of the background processing
});
});
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow