Ios 是否可以关闭当前未使用的UIAppFonts的文件描述符?
我们在iOS应用程序中捆绑了许多字体,并将它们全部放在Ios 是否可以关闭当前未使用的UIAppFonts的文件描述符?,ios,uiwebview,file-descriptor,uifont,uiappfonts,Ios,Uiwebview,File Descriptor,Uifont,Uiappfonts,我们在iOS应用程序中捆绑了许多字体,并将它们全部放在UIAppFonts中,以加快加载速度。 (我们在UIWebView中使用它们,它比使用@font-face加载文件快得多) 然而,这让我偶尔得到这样的警告: Mar 13 23:07:16 iPad afcd[2582] <Error>: Max open files: 78 Mar 13 23:07:17 iPad mobile_house_arrest[2584] <Error>: Max open files:
UIAppFonts
中,以加快加载速度。(我们在
UIWebView
中使用它们,它比使用@font-face
加载文件快得多)
然而,这让我偶尔得到这样的警告:
Mar 13 23:07:16 iPad afcd[2582] <Error>: Max open files: 78
Mar 13 23:07:17 iPad mobile_house_arrest[2584] <Error>: Max open files: 78
Mar 13 23:07:17 iPad mobile_house_arrest[2586] <Error>: Max open files: 78
Mar 13 23:07:17 iPad mobile_house_arrest[2587] <Error>: Max open files: 78
Mar 13 23:07:17 iPad mobile_house_arrest[2588] <Error>: Max open files: 78
对我们来说,这意味着大约有一百个打开的文件描述符,尽管目前使用的UIAppFonts
不超过五个。有时会出现重复条目
是否有强制关闭当前未使用的UIAppFonts的文件描述符的方法?
如果没有,是否有另一种方法使本地字体可供UIWebView
使用,而不必求助于速度较慢的@font-face
如果没有,是否有另一种方法可以让UIWebView使用本地字体,而不必求助于速度较慢的@font-face
事实证明,确实有
我们通过使用和注销字体来解决这个问题。这使它们可用于
UIWebView
,因为在字体系列中使用字体之前,您总是先注册字体
我在关闭与精灵工具包操作关联的文件描述符时遇到问题
playSoundFileNamed:
他们从不关门。因此,他们会吃掉文件描述符,直到应用程序崩溃。我想出了一个办法来关闭它们。我不明白为什么它对你的UIAppFonts不起作用
我修改了你在问题中引用的片段。这是我的修改版本
#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];
}
}
}
此init专门关闭NSFileHandle的dealloc上的文件描述符(这几乎是立即关闭的)
让我们知道它是否适用于您的UIAppFonts。现在在一个有120多种自定义字体的应用程序中遇到了这个问题。但不使用UIWebView,只使用自定义UILabels。。。我想是时候减少字体列表了…@Brad:我想这种方法也应该适用于UILabels。(除非您需要同时显示所有120多个)
#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];
}
}
}
NSFileHandle *loudBangHandle = [[NSFileHandle alloc] initWithFileDescriptor:fd closeOnDealloc:YES];