NSPOSIXErrorDomain Code=24 "Too many open files"

I am trying to write a line of data into txt file every 30 seconds and in each time I have open the file and close it carefully. (It will be run between two threads.For example this method is run in thread-A and call itself in thread-B, and in thread-B it call itself again and run in thread-A)

When my app runs for a long time(for example one night), it will give this error message: DebugLog:failed to append: Error Domain=NSCocoaErrorDomain Code=512 "(null)" UserInfo={NSFilePath=/var/mobile/Containers/Data /Application/DC61A031-1102-4D28-A28D-AD17E2AF0511/Documents/AppLogL1_1.txt, NSUnderlyingError=0x283c8fba0 {Error Domain=NSPOSIXErrorDomain Code=24 "Too many open files"}}

Can anyone tells me why this error occurs?

NSPOSIXErrorDomain Code=24 "Too many open files"
 
 
Q