assetTitle中的正斜杠会导致错误

时间:2017-10-30 12:20:44

标签: ios avassetdownloadtask

在测试时(在真实设备上)AVAssetDownloadURLSession我注意到当我将slash“/”放入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];

来自Apple的文档(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.

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

1 个答案:

答案 0 :(得分:0)

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

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