iosobjective-cavfoundationnsurlavurlasset

No known class method for selector 'URLAssetWithURL'


I have an iOS app which uses a lot of different audio files recorded in the app and saved. I have imported AVFoundation framework, however I still get the error:

No known class method for selector 'URLAssetWithURL'

Here is my code:

AVAsset *asset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:audioFiles[indexPath.row]]];
waveformView.asset = asset;

Inside the audioFiles array is a local URL like the following:

file:///var/mobile/Containers/Data/Application/6B35F9EA-1896-4989-91AF-06850B74B2E9/Documents/record_sound_1.aif

What am I doing wrong?


Solution

  • As per the class reference at https://developer.apple.com/library/mac/documentation/AVFoundation/Reference/AVURLAsset_Class/index.html

    the class method takes two parameters, the URL and some options. Change to:

    AVAsset *asset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:audioFiles[indexPath.row]] options:nil];
    waveformView.asset = asset;
    

    I would expect XCode's autocompletion and highlighting make it obvious that you were using a method that didn't exist...