NSURLSession

My app allows users to take photos which are uploaded via our web services. Currently I manage a queue of images that need to be uploaded and I send them up one-at-a-time so as to not overwhelm the app or our services. That works pretty well and it can safely resume from a termination, etc, so users aren’t losing images. But there’s a problem.

Some users have several hundred photos related to their workflow that need to be uploaded. As this upload takes some time, invariably either the idle timer kicks in or else the user takes a phone call or uses another app on their phone while this is happening and my app is suspended. Unless the user goes back to my app after each suspension, the uploads do not resume until the next time the user goes to use my app and many users are left wondering why their photos have not yet appeared in the right place within our web client despite the fact that they took them several days before…

I don’t think suspending the idle timer is the right approach for my app as there’s not necessarily any interaction occurring while the images are being uploaded and in any case this won’t solve the situation where a user simply backgrounds my app to do other things. From the research I’ve done, it seems that the better approach - if my app was in Xcode - would be to use the NSURLSession object in order to perform a background upload that would continue execution even if my app was suspended or terminated and would then notify my app, in background, to handle the completion of each upload.

Now I know Xojo doesn’t offer this out-of-the-box but I was wondering whether this might be something that could be solved via declares?

Have you set any entitlements to operate in the background for your app ?
That might do it as then you should not be outright suspended but allowed to operate in the background

I haven’t. Is there any documentation about how to do that?

Probably on Apples site since its not specific to Xojo

[quote=188868:@Jason Tait]it seems that the better approach - if my app was in Xcode - would be to use the NSURLSession object in order to perform a background upload that would continue execution even if my app was suspended or terminated and would then notify my app, in background, to handle the completion of each upload.

Now I know Xojo doesn’t offer this out-of-the-box but I was wondering whether this might be something that could be solved via declares?[/quote]
Jason, have implemented a lot of the NSURLSession stuff in iOSLib now (but not yet uploaded onto the repository). But it’s a whole framework in itself and some methods will initially be missing – let alone the time for myself to test all this stuff. If you like, I’ll inform you when it’s online and would be grateful on bug reports & missing pieces.

Thank you very much Ulrich!

As I needed this fairly quickly and it is important for my app, a couple of days ago I arranged to contract with another declare-Wizard from this forum to code it for my app.

However I’m very happy to take a look at your solution when it is ready, and provide feedback, as I’m sure there will be other useful things in your library too that might come in handy for my app. :slight_smile:

I’d be glad to have some feedback on this, Jason! I scraped together almost everything (you find the classes in https://github.com/UBogun/Xojo-iosLib – look into AppleSharedCore and there into Foundation – there is a folder AppleURLSession that should contain almost everything for URLSessions.)

After completing it, I realized I didn’t know what and where to up- and download, that’s why it’s currently fully untested. I couldn’t create the Wiki entries yet, but the classes are aligned to Apple’s docs except there is only one DelegateClass for all delegate types holding all the events and methods for each subclass and I did not create CompletionBlock templates except for Flush and Reset. Therefore every hints on bugs and easier set-up are highly welcome, as well as a demo view to add into the library.

Thanks a lot
Uli