1
我在主线程上呈现html页面。因此,我不能在主线程的同一线程上运行Pusher,因为它不断丢弃消息。在后台线程上运行推送器iOS
有没有办法在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
});
});
它是'滴'的信息是什么? –
新的通知进来了。当主线程正在使用时,它正在删除其中的一些。 – Jagdeep
你是否尝试使用一些NSOperation专门为此任务创建NSOperationQueue?为了清晰起见, –