Alfresco / alfresco-ios-sdk

19 stars 16 forks source link

Background network session not working #389

Open vburojevic opened 8 years ago

vburojevic commented 8 years ago

When favorites are syncing and app goes to background, sync is interrupted and it fails. I saw that there is a session parameter int the SDK kAlfrescoUseBackgroundNetworkSession,but when I set it, I get an error "A background URLSession with identifier Alfresco-iOS-SDdddK already exists!", and whole app communication stops working.

NSDictionary *sessionParameters = [@{kAlfrescoMetadataExtraction : @YES, kAlfrescoThumbnailCreation : @YES, kAlfrescoUseBackgroundNetworkSession : @YES} mutableCopy];

Is background download fully supported in Alfresco iOS SDK?

mikeh commented 8 years ago

Hi Vedran - and apologies for the delay with my reply. I'd missed the GitHub notification for your issue.

I suspect what you're seeing is that, yes - the SDK fully supports background networking, but we haven't yet added the correct behaviour to the app to manage the time iOS gives ongoing connections after an app is backgrounded. Recently all the networking code in the SDK was migrated from NSURLConnection to NSURLSession in order to support this mode, so it should work fine for third party apps written to the most recent app specifications from Apple.

We'll likely have some app-specific behaviours that will need updating - for example the NSOperations that the file sync part of the app uses needed fixing up for iOS 9. I suspect there are a few more areas like that before we're fully compliant.

Thanks, Mike

vburojevic commented 8 years ago

Hi Mike,

Thanks for the response!

So if I understand correctly, background sync should work in the latest Alfresco SDK? Can you please point me in the right direction on why the SDK keeps giving the message "A background URLSession with identifier Alfresco-iOS-SDK already exists!"?

It seems that there is a problem in the SDK code which keeps the httpRequest from initializing correctly with session params when background param is set to true.

I can't look at the implementation as it's in the static library, so not sure where is the root of the problem.

mikeh commented 8 years ago

Hmmm.. so that looks like the SDK isn't passing the right config down to the CMIS library. The latest version of the SDK pulls CMIS in as source code, so these things become easier to debug. I'll try to find some time over the next few working days to have a look at what's going on.

vburojevic commented 8 years ago

Ok great, thanks! Let me know! :)

mikeh commented 8 years ago

An update: I've taken a walk through the SDK and CMIS code to see where the error is being thrown. It looks like the place where the CMIS code creates new NSURLSession objects isn't really correct based on the Apple documentation; a new one is created for each CMISHttpRequest rather than one being managed by the CMISBindingSession.

Currently it's the CMISHttpRequest object that's handling the NSURLSession delegate callbacks too, to be notified on each task completion, so that would also need to be updated.

I'm not sure when I'll have time to work through and re-implement how this works. For now you'll have to manage background network requests separately rather than through the SDK/CMIS stack.

vburojevic commented 8 years ago

@mikeh Ok, thanks for the update!