Skip to main content

On-Demand Resources

Summary​

The SDK has the ability to use On-Demand Resources (ODR) so that apps can download the required resources on the fly and even do so "silently" without showing downloading UI.

Requirements​

  • You must be using a Static variant of our SDK because the resources (.bundle) file is separated from the framework.
  • The SDK can be integrated manually or via CocoaPods (1.11+).

Integration​

This first step is to integrate the SDK manually by following the manual installation guide to get the SDK up and running. If you have done this already then skip to the next step.

The second step is to set the "Enable On Demand Resources" (ENABLE_ON_DEMAND_RESOURCES) build setting to Yes for your app's target.

For the third step, you must tag the resources bundle (IncdOnboarding.bundle file) with the following tag: "IncdOmniResources". To do this, Open your Xcode project, select the IncdOnboarding.bundle file on your Project Navigator (left side, first tab). On the File Inspector (right side, first tab) there will be a section title "On Demand Resource Tags" with a textfield where you enter the tag.

For use with Cocoapods all you need to do is add pod 'IncdOnboarding/ODR' inside your podfile. Run pod install and thats it. Make user you are using CocoaPods 1.11+ and IncdOnboarding SDK 4.1.0+

Usage​

There are three methods in the SDK to use for ODR.

  • checkOnDemandResourcesAvailablity(completion:)​

Checks if On-Demand Resources have been downloaded (and that they are still present) on the device. The completion handler returns a boolean flag indicating if the resources are present or not.

  • downloadOnDemandResources(showUI:vc:onProgress:onCompleted:onError:)​

Starts downloading the On-Demand Resources if they are not present on the device. There are five parameters for this method.

  1. The showUI boolean flag, if true the SDK should show its standard UI for downloading resources. If the flag is set to false the download will start "silently" without showing the SDK's downloading UI. If you wish, you may show your own UI for downloading.
  2. If showUI is set to true, then the SDK's downloading UI will be presented on the UIViewController passed into the vc parameter.
  3. The onProgress handler receives a double value which indicates the progress of the download.
  4. The onCompleted handler is called when that download is completed. If the resources are already present the onCompleted handler is called immediately.
  5. The onError handler is called when an error occurred.

Notifies the system that the On-Demand Resources are no longer needed. The completion callback from downloadOnDemandResources(showUI:vc:onProgress:onCompleted:onError:) or checkOnDemandResourcesAvailablity(completion:) must have completed before calling removeOnDemandResources().

Support​

  • You may initialize the SDK using initIncdOnboarding(url:apiKey:loggingEnabled:testMode:_:) before or after downloading resources.
  • You must download the resources before calling any of the onboarding methods on IncdOnboardingManager. Failure to do so will result in the methods returning a .resourcesNotFound error.
  • If you are showing the SDKs standard downloading UI, dont forget to dissmiss it (or show the next upcoming screen) in the onCompleted handler.
  • You may show the standard downloading UI even if the download has been started before and is still downloading, check Scenario 3.
  • If you are testing your app through a distribution platform (Bitrise, AppCenter etc.), please be aware of the "Embed Asset Packs In Product Bundle" (EMBED_ASSET_PACKS_IN_PRODUCT_BUNDLE) build setting.
  • For App Store production, please host the resources on your server, more information can be found on Apple's official documentation.

Example usage:​

Scenario 1:​

Start download and show standard SDK UI, once finished start onboarding:

IncdOnboardingManager.shared.downloadOnDemandResources(
showUI: true,
vc: self,
onCompleted: {
// start the onboarding
IncdOnboardingManager.shared.startOnboarding(config: config, delegate: self)
}
)

Scenario 2:​

Start downloading silently:

IncdOnboardingManager.shared.downloadOnDemandResources(onCompleted: { 
// Handle accordingly, if needed
},
onError: { error in
// Handle accordingly, if needed
}
)

Scenario 3:​

Start download silently, and later on show the standard downloading UI if the download is still not finished:

// Somewhere in the begining of the app.
IncdOnboardingManager.shared.downloadOnDemandResources()
...
// User is using other parts of the app regularly.
...
// Now the User wants to start onboarding.
IncdOnboardingManager.shared.downloadOnDemandResources(
showUI: true,
vc: self,
onCompleted: {
// start the onboarding
IncdOnboardingManager.shared.startOnboarding(config: config, delegate: self)
}
)

Scenario 4:​

Download using my apps own downloading UI:

IncdOnboardingManager.shared.downloadOnDemandResources(
showUI: false,
vc: nil,
onProgress: { progress
myDownloadViewController.progress = progress
},
onError: {
// Handle accordingly
}
)

Scenario 5:​

We just want to find out if the resources have been downloaded and if they are present on the device:

IncdOnboardingManager.shared.checkOnDemandResourcesAvailablity(completion: { isPresent in
if isPresent {
// Resources have been downloaded and are present on device.
} else {
// Resources have not been downloaded or have been deleted.
}
})