1

我正在尝试将 Fairplay 集成到 Apple TV 应用程序中。到目前为止,我请求了证书,但是当我尝试获取 SPC 时它失败了,它返回一个错误:“操作无法完成”。我可以做些什么来调试这个,或者你有一些 Fairplay 流 url 用于测试?

- (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);

  }];
}

'requestBytes' 为空。

谢谢你,克劳迪乌

4

0 回答 0