gpt4 book ai didi

iOS8 EXC_BAD_ACCESS 执行时 [[NSString alloc] initWithFormat :format arguments:argList]

转载 作者:行者123 更新时间:2023-12-02 00:31:53 27 4
gpt4 key购买 nike

以下代码在 iOS7 上运行良好。当我在 Xcode6/iOS 上运行时它崩溃了。

+ (void)log:(NSString *)format arguments:(va_list)argList
{
NSLogv(format, argList);

if ([self sharedConsole].enabled)
{
NSString *message = [[NSString alloc] initWithFormat:format arguments:argList]; //Crash here with info of EXC_BAD_ACCESS
if ([NSThread currentThread] == [NSThread mainThread])
{
[[self sharedConsole] logOnMainThread:message];
}
else
{
[[self sharedConsole] performSelectorOnMainThread:@selector(logOnMainThread:)
withObject:message waitUntilDone:NO];
}
}
}

最佳答案

我也有同样的问题!

NSLogv 在 iOS8 上的实现变化

我的解决方案:关闭 va_list 并在每次使用之间重新初始化它。

+ (void)log:(NSString *)format arguments:(va_list)argList
{
va_start(argList,format) ;
NSLogv(format, argList);
va_end(argList) ;

va_start(argList,format) ;
if ([self sharedConsole].enabled)
{
NSString *message = [[NSString alloc] initWithFormat:format arguments:argList]; //Crash here with info of EXC_BAD_ACCESS
if ([NSThread currentThread] == [NSThread mainThread])
{
[[self sharedConsole] logOnMainThread:message];
}
else
{
[[self sharedConsole] performSelectorOnMainThread:@selector(logOnMainThread:)
withObject:message waitUntilDone:NO];
}
}
va_end(argList) ;
}

(Tof,以前@user2424230)

关于iOS8 EXC_BAD_ACCESS 执行时 [[NSString alloc] initWithFormat :format arguments:argList],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25911238/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com