0

What I am trying to do:- I am trying to build a custom SDK (via swift package manager) which my clients will just import and leverage the features. My custom SDK helps connect devices and then read data. I am fusing some cloud uploading functionality in my SDK, which basically uploads the data to our server, cause we also want that data.

Problem:- Now, the problem is to make sure that uploading of data happens. I am planning to create a background service which would continuously run and make sure that any not-uploaded files gets uploaded. The problem is IOS doesn't have an option like Services (like in Android) and I am seeing that Background-Fetch could work.

But The real issue is that I am building an SDK.

So, my question:- Is it even possible to make background fetch functionality available in an SDK/ swift package?

Siddharth Choudhary
  • 1,069
  • 1
  • 15
  • 20

1 Answers1

0

Yes, it's possible! But you will need to pass some instructions to your clients because the Background Fetch will need to be configured directly in the app and not in the SDK.

You can create your own function to implement background fetch

public func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { ... }

and your client will call this function in their application. Something like this

public func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { 
    YourSDK().application(...)
}

Also, remember that the app needs to add the Background Fetch capability

  • I am actually trying to make it as simple as possible for my client and so passing them instructions wouldn't be the best approach here. Also, I am trying to implement something where this stays in our control and not the client. Cause we want to make sure that this background fetch is always running. Clients can easily bypass this step if we leave it up to them. – Siddharth Choudhary Apr 28 '21 at 16:28
  • I understand. Unfortunately I really believe that Apple does not give us a way to make this functionality entirely within an SDK. As far as I know, capabilities should be added to the application – Izabella Melo Apr 28 '21 at 19:04
  • Okay, Thanks for the answer though! – Siddharth Choudhary Apr 28 '21 at 19:28