2014-03-29 21 views
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 
     }); 
    }); 
+0

它是'滴'的信息是什麼? –

+0

新的通知進來了。當主線程正在使用時,它正在刪除其中的一些。 – Jagdeep

+0

你是否嘗試使用一些NSOperation專門爲此任務創建NSOperationQueue?爲了清晰起見, –

回答

0

我最終在主線程中使用它,並在主線程上放了很多其他功能。似乎到目前爲止工作得很好。