【发布时间】:2014-03-29 14:49:04
【问题描述】:
我正在主线程上渲染 html 页面。因此,我无法在与主线程相同的线程上运行 Pusher,因为它不断丢弃消息。
有没有什么方法可以在 iOS 的后台线程上始终运行 Pusher?
我尝试过 Grand Central Dispatch,但它不起作用,因为在初始化后,Pusher 又回到了主线程。
谢谢
这是我目前所拥有的。
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
});
});
【问题讨论】:
-
它“丢弃”的信息是什么?
-
进来的新通知。在使用主线程时,它正在删除其中的一些通知。
-
您是否尝试在专门为此任务创建的 NSOperationQueue 中使用一些 NSOperation?
-
为了清楚起见添加了一些源代码
标签: ios multithreading pusher