title: iOS / Swift : Receive callbacks from data streaming service without push notifications while app is in background
body: <p><em>The Background Information:</em> </p>
  
  <p>I am writing an application that uses the PubNub framework to directly couple one Raspberry Pi with one iPhone, for each individual user. The Raspberry Pi uses an Arduino as a slave to gather analog data, then uses the PubNub network to publish that data to the one and only iPhone that is on the same channel. With the data that the iPhone receives, it determines (locally) if the user needs to be alerted. Then, when the user is alerted, they have the ability to adjust the current state of the Raspberry Pi by sending data (settings) back to the Pi, which will then resolve the problem that warranted a user alert. </p>
  
  <p><em>The Problem:</em> </p>
  
  <p>When the iPhone app goes into the background, the messages sent by the Raspberry Pi that the iPhone should be receiving will no longer be caught by the application, and therefor the user is no longer notified when they need to be. The first obvious solution would be to move the logic of what warrants an alert to the Raspberry Pi itself, so that it can use Apple Push Notifications to send those alerts to the user. However, the problem with this is that I am also trying to track whether or not the Raspberry Pi connection has timed out, so that if some unexpected disconnect occurs, the user is notified of that problem as well. This logic <em>obviously</em> can not be on the Raspberry Pi itself, because if a disconnect occurs, then it will not be able to push the notification to the iPhone itself. Having a middle man server of sorts to monitor the state of the device would seem like a logical solution... however I <strong><em>do not</em></strong> want anything other than the iPhone and Raspberry Pi involved in the data transmission and handling, which is clearly the entire motivation behind using PubNub in the first place (within the scope of my application).</p>
  
  <p>This is not a PubNub specific problem. I only cite them to paint a clearer picture. Also worth noting is that I <strong><em>do not</em></strong> want to fake a location service in order to get iOS to grant continuous background permissions. This is a lazy and sloppy solution with undesired overhead. </p>
  
  <p><em>The Question:</em></p>
  
  <p>How do I receive (or request) a short string every 15 to 30 seconds in the background to determine if I should throw an alert. This has to be achievable. Based on my research and reading of apple documentation, it is clear to me that many people will try to respond with "it isn't possible." <strong>I do not welcome this answer</strong>. I am here to find a solution that I could not previously find, or that has not previously been proposed. I need an intelligent engineer to propose a genuine solution or workaround to my problem. </p>
  
  <p>I sincerely thank the champion engineer in advance. </p>