I was having trouble with closing file descriptors associated with a Sprite Kit action,
playSoundFileNamed:
They never close. So they eat up file descriptors until the app crashes. I figured out a way to close them. I don't see why it wouldn't work for your UIAppFonts.
I modified the snippet you referenced in your question. This is my modified version,
#import <sys/types.h>
#import <fcntl.h>
#import <errno.h>
#import <sys/param.h>
-(void)closeFileDescriptorsForSounds
{
int flags;
int fd;
char buf[MAXPATHLEN+1] ;
int n = 1 ;
for (fd = 0; fd < (int) FD_SETSIZE; fd++) {
errno = 0;
flags = fcntl(fd, F_GETFD, 0);
if (flags == -1 && errno) {
if (errno != EBADF) {
return ;
}
else
continue;
}
fcntl(fd , F_GETPATH, buf ) ;
NSLog( @"File Descriptor %d number %d in use for: %s",fd,n , buf ) ;
++n ;
// My modifications to the snippet...
NSString *str = [NSString stringWithUTF8String:buf];
NSString *theFileName = [str lastPathComponent];
if ([theFileName isEqualToString:@"LoudBang.mp3"])
{
NSLog(@"FD is LoudBang");
NSFileHandle *loudBangHandle = [[NSFileHandle alloc] initWithFileDescriptor:fd closeOnDealloc:YES];
}
else if ([theFileName isEqualToString:@"QuietBang.mp3"])
{
NSLog(@"FD is QuietBang");
NSFileHandle *quietBangHandle = [[NSFileHandle alloc] initWithFileDescriptor:fd closeOnDealloc:YES];
}
}
}
I converted buf to a string and then isolated the file name. Then I compared the file name to a known file I want to close. When a file I want to close is found the code creates an NSFileHandle around the file descriptor using the following,
NSFileHandle *loudBangHandle = [[NSFileHandle alloc] initWithFileDescriptor:fd closeOnDealloc:YES];
This init specifically closes the file descriptor on dealloc of the NSFileHandle (which will be almost immediately).
Let us know if it works for your UIAppFonts.