Netrunner
Netrunner

Reputation: 53

Detect a new picture has been taken while in background

I have been struggling for quite some time on this issue. I have an app that runs on iPhone (>= iOS7) where I need to pick all the pictures that the user takes (after asking for camera access, of course) and upload them if they meet a certain criterium. Obviously, since the user is taking the pictures from the camera app and not from inside my app, when the picture is taken, my app is backgrounded, and not always do the users re-open the app after taking their pictures. As I don't use GPS/VoIP/Accessory in my app, I don't have these permissions enabled in my app's plist (I only have fetch and notifications enabled, as I use these). To know that a user has taken a new picture, I have tried two different approaches: (1) using an observer and (2) retrieving the last pictures from ALAssetLibrary, keeping the last picture creation date in memory and comparing it to the latest pictures retrieved. Both of these work well when the app runs in foreground (meaning if i awake my app and execute them, I can get the pics correctly with either of these methods) but I haven't found a way to make either of the methods work in background. In the first case, the observer only gets the notification when the app is in foreground OR for the first three minutes if I have any long running task running (which have a 3 minutes limit). In the second case, the problem is similar (I run the scan on a long running background task, let it sleep after scanning for 2 minutes then launch ANOTHER background task that do the same); it seems that even if I spawn multiple background task one inside the other the 3 minutes time limit is still enforced across tasks... I am sure there is a way to achieve this, as I have seen at least one other app on the App Store that does EXACTLY this, without any of the special permissions (VoIP/GPS/Accessory etc). Anyone has a tip to get me on the right way to achieve this? Thanks in advance!

Upvotes: 2

Views: 184

Answers (0)

Related Questions