0

I am doing the preliminary research for an app that has already been implemented for Android. The app needs to be able to perform some calculations at plug-in and then, at the calculated time intervals, send messages to the USB device. These intervals are likely to span hours.

In Android, the application utilizes the AlarmManager API in order to run the communication code at those intervals. However, as iOS does not have an equivalent API, I am wondering if this is possible. I have researched the External Accessory framework and am finding that it is rather vaguely defined. I have looked through SO and found a few relevant answers, here and here, however they seem to say that the USB device must initiate communication and the EASession cannot have NSTimers running in the limited background state.

Is it possible to set a timer for hours away that will trigger some code to be ran which will in-turn trigger a message to be sent to the External Accessory if the application includes "external-accessory" as a Background Mode? Or does the application only remain in background mode as long as it is receiving messages from the connected accessory?

Community
  • 1
  • 1
advdev1234
  • 30
  • 8
  • check this http://stackoverflow.com/questions/25406254/ios-nstimer-run-in-background-for-check-alarm-time-is-equal-to-current-time-and – casillas Oct 28 '15 at 21:49
  • There is no way to schedule code to execute at a specific time on iOS when your app is in the background. – Paulw11 Oct 28 '15 at 21:51
  • @Paulw11 Regardless of if that background mode is extended due to the external accessory? – advdev1234 Oct 28 '15 at 22:21
  • There are two types of background mode in iOS - Your app can be in the background and waiting for an event or in the background executing code in response to an event. An app can stay in the background waiting for an event for a long time but it can be eventually removed by iOS if memory is needed or the user can kill the task. When an event such as an update to device location or a push notification triggers execution in the background you only have a few seconds to execute to handle that event. – Paulw11 Oct 28 '15 at 22:34
  • MFi accessories that are connected through the external accessory framework can send an event to "wake" your app as I described in my previous comment and your app then has a few seconds in the background to process the update, but external accessory background mode does not provide extended, continuous, execution of code in the background, this includes waiting for an NSTimer to fire – Paulw11 Oct 28 '15 at 22:39
  • Okay gotcha, that is what I was afraid of. Looks like we shall have to do some hardware re-design then. Thanks much @Paulw11 ! – advdev1234 Oct 28 '15 at 22:40
  • Sorry, @Paulw11 but do you happen to know where I might find exactly how many seconds the app has to respond to the accessory on wake-up? – advdev1234 Oct 28 '15 at 22:50
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/93630/discussion-between-paulw11-and-advdev1234). – Paulw11 Oct 28 '15 at 22:50
  • @advdev1234 were you able to find a good solution to this? I have a very similar issue where I need to read data over a period of many hours from the MFi accessory by sending a command to the accessory at set time intervals while the app is backgrounded. – sublimepremise Dec 27 '19 at 21:21

0 Answers0