How to play audio from NSData in a library in Objective C

I'm trying to play an audio content built from NSData inside a library (.a). It works properly when my code is inside an app. But it is not working when in a library, I get no error and no sound playing.

NSError * errorAudio = nil;
NSError * errorFile;

// Clear all cache
NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
for (NSString *file in tmpDirectory) {
    [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
}

// Set temporary directory and temporary file
NSURL * tmpDirURL = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES];

NSURL * soundFileURL = [[tmpDirURL URLByAppendingPathComponent:@"temp"] URLByAppendingPathExtension:@"wav"];

[[NSFileManager defaultManager] createDirectoryAtURL:tmpDirURL withIntermediateDirectories:NO attributes:nil error:&errorFile];

// Write NSData to temporary file
NSString *path= [soundFileURL path];
[audioToPlay writeToFile:path options:NSDataWritingAtomic error:&errorFile];

if (errorFile) {
    // Error while writing NSData
} else {
    // Init audio player
    self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:&errorAudio];
    if (errorAudio) {
        // Audio player could not be initialized
    } else {
        // Audio player was initialized correctly
        [audioPlayer prepareToPlay];

        [audioPlayer stop];
        [audioPlayer setCurrentTime:0];
        [audioPlayer play];
    }
}

I don't check errorFile intros piece of code, but when debugging I can see that value is nil.

My header file

#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>

@property(nonatomic, strong) AVAudioPlayer * audioPlayer;

My m file

#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>

@synthesize audioPlayer;

I've been checking for dozens of posts but cannot find any solution, it always works properly in an app, but not in a library. Any help would be greatly appreciated.

How to play audio from NSData in a library in Objective C
 
 
Q