Importing the licences
The client application must get pre-delivered licences for offline consumption of protected content, for example, downloaded content. With direct initialisation, the PAK handles the predelivery of licences between the server and the PAK. These will be available for both online and offline content.
If the client application needs to import the licenses again, it must request a call to prefetchLicenses and listen for the LICENSE_PREFETCHING_DONE notification.
Example code
The following code samples show how to prefetch licenses in direct mode.
Set up the notification and listener
- (id)init
{
if (self = [super init])
{
// set up notification for the listener
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(prefetchStateChanged) name:@"PreDeliveryStateChanged" object:nil];
PakCore *pPakCore = PakCore :: pgGetInstance();
IPakCoreDrmAgent *pDrmAgent = pPakCore->pGetDrmAgent();
_prefetchListener = new NMPPakCoreNotifListener(@"PreDeliveryStateChanged");
pDrmAgent->addPrefetchLicensesStateChangedListener(*_prefetchListener);
}
return self;
}
Set up the notification method
- (void) prefetchStateChanged
{
PakCore *pPakCore = PakCore :: pgGetInstance();
IPakCoreDrmAgent *pDrmAgent = pPakCore->pGetDrmAgent();
if (pDrmAgent->getLicensePrefetchingState() == NMP::LICENSE_PREFETCHING_DONE &&
pDrmAgent->getLastCommunicationStatus() == NMP::COMMUNICATION_STATUS_OK)
{
// Success!
}
}
Add a method to fetch the licenses
// prefetchLicenses parameters are string, string, string, bool
- (void) someMethod
{
PakCore *pPakCore = PakCore :: pgGetInstance();
IPakCoreDrmAgent *pDrmAgent = pPakCore->pGetDrmAgent();
if (pDrmAgent->getState()== IPakCoreDrmAgent::PAK_READY)
pDrmAgent->prefetchLicenses(protectedPrivateData,
clearPrivateData,
serverURL,
willPersist);
// method is asynchronous. Prefetch state available via prefetchStateChanged
}
Next step: You can start the download.