1

I am trying to integrate Fairplay to an Apple TV app. So far, I requested the certificate but when I try to get the SPC it fails, it returns an error: "The operation couldn't be completed". What can I do to debug this, or do you have some Fairplay streaming urls for testing?

- (void)requestApplicationCertificateWithCompletion:(AppCertificateRequestCompletion)completion {
    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
    NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
    NSURL *url = [NSURL URLWithString:self.certificateUrl];
    NSURLSessionDataTask *requestTask = [session dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        completion(data);
    }];
    [requestTask resume];
}

- (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForRenewalOfRequestedResource:(AVAssetResourceRenewalRequest *)renewalRequest {
    return [self resourceLoader:resourceLoader shouldWaitForLoadingOfRequestedResource:renewalRequest];
}

- (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest {

    NSURL *url = loadingRequest.request.URL;

    AVAssetResourceLoadingDataRequest *dataRequest = loadingRequest.dataRequest;

    [self requestApplicationCertificateWithCompletion:^(NSData *certificate) {
          NSString *assetStr = [url.absoluteString stringByReplacingOccurrencesOfString:@"skd://" withString:@""];
          NSData *assetId = [NSData dataWithBytes: [assetStr cStringUsingEncoding:NSUTF8StringEncoding] length:[assetStr lengthOfBytesUsingEncoding:NSUTF8StringEncoding]];

             // To obtain the license request (Server Playback Context or SPC in Apple's terms), we call
             // AVAssetResourceLoadingRequest.streamingContentKeyRequestData(forApp:contentIdentifier:options:)
             // using the information we obtained earlier.

            NSError *error = nil;
            NSData *requestBytes = [loadingRequest streamingContentKeyRequestDataForApp:certificate
                                                                      contentIdentifier:assetId
                                                                                options:nil
                                                                                  error:&error];

             NSLog(@"%@", error);
             NSLog(@"%@", requestBytes);

  }];
}

The 'requestBytes' is null.

Thank you, Claudiu

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
claudiudbc
  • 21
  • 7
  • Can you share your `assetStr` prior to removing the `skd://` prefix? I suspect the content provider may have its own prefix you need to trim also. I don't see where you're using this either, `AVAssetResourceLoadingDataRequest *dataRequest = loadingRequest.dataRequest;`. You'll need to return a `BOOL` in `shouldWaitForLoadingOfRequestedResource` too. Everything else looks fine. – Daniel Storm Jun 10 '20 at 20:05

0 Answers0