在后台线程iOS上运行push



我在主线程上渲染html页面。因此,我不能在与主线程相同的线程上运行push,因为它会不断丢弃消息。

是否有办法在iOS的后台线程上始终运行push ?

我已经尝试了Grand Central Dispatch,但它不工作,因为初始化后,push返回主线程。

谢谢

这是我目前所掌握的。

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
        });
    });

我最终在主线程上使用它,并在主线程上删除了许多其他功能。

最新更新