6

Context: I have Been using an iOS python IDE app (Pythonista) to write some simple scripts that periodically executes post/get requests, interprets & analyses these requests and then finally notifies me using builtin iOS notifications.

I have been running these scripts on my phone as I take it everywhere and getting a push notification for this information is highly useful to me.

Problem statement: When I execute a long-running script in Pythonista, and shift the app to the background i.e. my switching to another app or by locking the phone, code execution suspends after a few minutes, effectively making the script redundant for my purposes (code execution and therefore notifications are suspended). This is intended by apple in it's design to allow the system to manage resources and load to prolong battery life (ref: https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html)

I'm looking for options to bypass (or manage) this restriction in iOS and can range from perhaps another python IDE that has increased permissions in its implementation to jail breaking the phone (but ideally i would like to avoid this).

Thanks guys, just shoot if anyone requires more clarification.

Note: There are other questions on SO that are similiar, but the majority are referring to writing an iOS app from scratch (xcode) so have increased access to permissions handling and background refresh/fetch features, something I don't as I am writing python natively in an iOS IDE.

Sighonide
  • 600
  • 4
  • 15
  • 1
    You have the wrong platform for what you want to do. iOS devices don't support that sort of background execution. Jailbreaking may be an option for you. – Paulw11 Jan 21 '18 at 02:34
  • Yeah that’s why I’m looking for options, given that this is the platform I’m using. I understand I could do other things like build an app from scratch etc but this is quick and painless (well apart from this part haha), I could also use a virtual private server online and have it send me notifications through other apps like Facebook messenger, but like I said, I’m looking for options given my current platform. - I’m hoping I don’t have to resort to jail breaking. – Sighonide Jan 21 '18 at 02:56
  • 1
    Paulw11 gave you your answer. Apple doesn't allow this. You could "game the system" by making your app a background music playing app and have it constantly play a silent sound. That would keep the app running in the background. It would cause Apple to reject your app from the app store, and would drain the battery on your phone very quickly, but it is possible. – Duncan C Jan 21 '18 at 03:25
  • You guys know if android has this same restriction? if there really is no way to do it natively in iOS, perhaps I should be thinking about changing OS's, at least it would still be on a phone, retaining the premise of my question. – Sighonide Jan 24 '18 at 23:54
  • Apple certainly allows this; many apps perform tasks in the background for periodic updates (navigation units commonly do so). “apps that need to download and process new content regularly” are specifically one of the use cases for this in the link the OP provided. That said, I’m not aware that Pythonista supports this. – Jerry Stratton Jan 25 '18 at 20:48
  • Best I can suggest is roll this as a Google AppEngine or AWS app. There are several libraries around designed to work on these platforms for generating notifications, and they provide very easy to use app hosting options. You can go through registering and get a POC app up and running in under an hour, and your Pythonista code should be highly portable to them, except for the notification API calls. – Simon Hibbs May 04 '18 at 13:56
  • Just had a quick read of Google AppEngine and it sounds like something I’ve been chasing recently (online VPS / application hosting so I don’t have to deal with infrastructure), so thanks for that, I’ll have a closer look. – Sighonide May 07 '18 at 05:00
  • Silent push notifications and background modes can be used for this (with limitations) in native apps using Cocoa Touch (Swift or Obj-C), but I’m not aware of any way to do this from the Pythonista platform. – Chris May 27 '18 at 20:04
  • Just thought i would drop a note here regarding this. After everyone's comments, unfortunately there isn't currently a feasible method to achieve what I wanted, however the above suggestions are still valuable for someone who needs specifically to have the scripts running on iOS and builtin notifications used (initially me). I eventually decided to have the scripts running on a raspberry Pi with notifications being sent to my phone via the Telegram app (using a Telegram bot running on the Pi). – Sighonide Jul 10 '18 at 12:57
  • Would this be possible if Pythonista showed up in the list under Settings / Background App Refresh? I am not seeing it there, so no way to enable from what I can see. It seems like there are many apps that communicate in the background with a server. – Balazs Rau Aug 08 '22 at 19:08

0 Answers0