资产标题中的正斜杠会导致错误



在测试(在真实设备上)AVAssetDownloadURLSession时,我注意到当我将斜杠"/"放入assetTitle时,结果我收到错误:

Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could 
not be completed" UserInfo={NSLocalizedDescription=The operation could 
not be completed, NSLocalizedFailureReason=An unknown error occurred 
(-12780)}

示例代码:

AVAssetDownloadTask * assetDownloadTask = [urlSession 
assetDownloadTaskWithURLAsset:urlAsset assetTitle:@"One two three 
(open/close)" assetArtworkData:nil options:nil];

来自苹果的文档(https://developer.apple.com/documentation/avfoundation/avassetdownloadurlsession/1650938-assetdownloadtaskwithurlasset):

title
A human readable title for this asset in the user's preferred language. 
This value will be displayed in the usage pane of the Settings app.

我认为上面的例子非常人性化。我是否需要将斜杠视为特殊字符并以某种方式对其进行转义以正确分配它?

是的,目前我需要在我的标题上执行此操作:

 NSCharacterSet *setToRemove = [NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 "];
 NSCharacterSet *setToKeep = [setToRemove invertedSet];
 NSString *downloadTitle = [[[item getTitle] componentsSeparatedByCharactersInSet:setToKeep] componentsJoinedByString:@""];

相关内容

  • 没有找到相关文章

最新更新