Forward slash in assetTitle causes error

105 Views Asked by At

While testing (on real device) AVAssetDownloadURLSession I noticed when I put slash "/" into assetTitle as result I receive error:

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)}

Example code:

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

From Apple's documentation (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.

I think above example is quite human readable. Do I need to treat slash as a special character and escape it somehow to assign it properly?

1

There are 1 best solutions below

0
On

Yes currently I need to do this on my titles:

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