2

当我尝试在 IOS6 设备中运行时,我的应用程序崩溃了。但它在模拟器中运行良好,通过 xcode 进行调试,并且它也在 IOS 7 设备中顺利运行。问题仅适用于 IOS 6 设备。这是我的控制台历史

<Error>: *** Terminating app due to uncaught exception'NSFileHandleOperationException', 
 reason: '*** -[NSConcreteFileHandle writeData:]: Bad file descriptor'
-iPhone ReportCrash[5485]
   <Notice>: Formulating crash report for process [5482]
   (UIKitApplication:[0x7046][5482])
    <Warning>: (UIKitApplication:[0x7046]) Jobappears to have crashed: Abort trap:    6

     <Warning>: Application 'UIKitApplication:[0x7046]'  
    exited abnormally with signal 6: Abort trap: 6

这是我的设备日志历史记录...

Incident Identifier: C7947F65-AD9A-4C9A-9A64-B9E3CF3C3003
CrashReporter Key:   b5b0efe726413c3f18049e973c20792dc187d12e
Hardware Model:      iPhone5,1
Process:         PhytterDock [6121]
  Path:            /var/mobile/Applications/FEB77102-11A1-4A8B-8700-  C2EE2C3E9289/PhytterDock.app/PhytterDock
Identifier:      PhytterDock
Version:         ??? (???)
Code Type:       ARM (Native)
            0x3991295e objc_exception_throw + 26
    0x39d7cfb2 pthread_kill + 54
2   libsystem_c.dylib               0x39db9366 abort + 90
3   libc++abi.dylib                 0x39361dda abort_message + 70
4   libc++abi.dylib                 0x3935f094 default_terminate() + 20
5   libobjc.A.dylib                 0x39912a58 _objc_terminate() + 144
6   libc++abi.dylib                 0x3935f118 safe_handler_caller(void (*)()) + 76
7   libc++abi.dylib                 0x3935f1b0 std::terminate() + 16
8   libc++abi.dylib                 0x39360626 __cxa_rethrow + 90
9   libobjc.A.dylib                 0x399129b0 objc_exception_rethrow + 8
10  CoreFoundation                  0x31b5e29c CFRunLoopRunSpecific + 452
11  CoreFoundation                  0x31b5e0c4 CFRunLoopRunInMode + 100
12  GraphicsServices                0x3573d336 GSEventRunModal + 70
13  UIKit                           0x33a7a2b4 UIApplicationMain + 1116
14  PhytterDock                     0x000cf6d4 main (main.m:15)
15  libdyld.dylib                   0x39d3fb1c start + 0

 Thread 1:
  0   libsystem_kernel.dylib            0x39e06d98 __workq_kernreturn + 8
 1   libsystem_c.dylib              0x39d54ad6 _pthread_workq_return + 14
 2   libsystem_c.dylib              0x39d547f2 _pthread_wqthread + 362
 3   libsystem_c.dylib              0x39d54680 start_wqthread + 4

 Thread 2 name:  Dispatch queue: com.apple.libdispatch-manager
 Thread 2:
0   libsystem_kernel.dylib          0x39df65d0 kevent64 + 24
1   libdispatch.dylib               0x39d31d22 _dispatch_mgr_invoke + 806
2   libdispatch.dylib               0x39d2d374 _dispatch_mgr_thread + 32

Thread 3 name:  WebThread
 Thread 3:
  0   libsystem_kernel.dylib            0x39df5e30 mach_msg_trap + 20
  1   libsystem_kernel.dylib            0x39df5fd0 mach_msg + 48
  2   CoreFoundation                    0x31bec2b6 __CFRunLoopServiceMachPort + 126
  3   CoreFoundation                    0x31beb02c __CFRunLoopRun + 900
  4   CoreFoundation                    0x31b5e238 CFRunLoopRunSpecific + 352
  5   CoreFoundation                    0x31b5e0c4 CFRunLoopRunInMode + 100
  6   WebCore                           0x37b66390 RunWebThread(void*) + 440
  7   libsystem_c.dylib                 0x39d5f0de _pthread_start + 306
  8   libsystem_c.dylib                 0x39d5efa4 thread_start + 4

 Thread 4:
 0   libsystem_kernel.dylib         0x39e06d98 __workq_kernreturn + 8
 1   libsystem_c.dylib              0x39d54ad6 _pthread_workq_return + 14
 2   libsystem_c.dylib              0x39d547f2 _pthread_wqthread + 362
 3   libsystem_c.dylib              0x39d54680 start_wqthread + 4

 Thread 5 name:  com.apple.NSURLConnectionLoader
 Thread 5:
  0   libsystem_kernel.dylib            0x39df5e30 mach_msg_trap + 20
  1   libsystem_kernel.dylib            0x39df5fd0 mach_msg + 48
  2   CoreFoundation                    0x31bec2b6 __CFRunLoopServiceMachPort + 126
  3   CoreFoundation                    0x31beb02c __CFRunLoopRun + 900
  4   CoreFoundation                    0x31b5e238 CFRunLoopRunSpecific + 352
  5   CoreFoundation                    0x31b5e0c4 CFRunLoopRunInMode + 100
  6   Foundation                        0x324ab888 +[NSURLConnection(Loader) _    resourceLoadLoop:] + 304
  7   Foundation                        0x3252f22c __NSThread__main__ + 968
  8   libsystem_c.dylib                 0x39d5f0de _pthread_start + 306
  9   libsystem_c.dylib                 0x39d5efa4 thread_start + 4

 Thread 6:
 0   libsystem_kernel.dylib         0x39e06d98 __workq_kernreturn + 8
 1   libsystem_c.dylib              0x39d54ad6 _pthread_workq_return + 14
 2   libsystem_c.dylib              0x39d547f2 _pthread_wqthread + 362
 3   libsystem_c.dylib              0x39d54680 start_wqthread + 4

Thread 7:
 0   libsystem_kernel.dylib         0x39e06d98 __workq_kernreturn + 8
 1   libsystem_c.dylib              0x39d54ad6 _pthread_workq_return + 14
 2   libsystem_c.dylib              0x39d547f2 _pthread_wqthread + 362
 3   libsystem_c.dylib              0x39d54680 start_wqthread + 4

Thread 8 name:  com.apple.CFSocket.private
Thread 8:
0   libsystem_kernel.dylib          0x39e06594 __select + 20
1   CoreFoundation                  0x31bf0474 __CFSocketManager + 676
2   libsystem_c.dylib               0x39d5f0de _pthread_start + 306
3   libsystem_c.dylib               0x39d5efa4 thread_start + 4

Thread 0 crashed with ARM Thread State (32-bit):
r0: 0x00000000    r1: 0x00000000      r2: 0x00000000      r3: 0x3b8c8524
r4: 0x00000006    r5: 0x3b8c8b78      r6: 0x1ed7ea14      r7: 0x2fd32a04
r8: 0x1ed7e9f0    r9: 0x00000888     r10: 0xffffffff     r11: 0x00000004
ip: 0x00000148    sp: 0x2fd329f8      lr: 0x39d7cfb7      pc: 0x39e06350
 cpsr: 0x00000010
4

2 回答 2

3

我不确定为什么它会是 ios6 特定的,因为它崩溃的原因就在那里

* -[NSConcreteFileHandle writeData:]: 错误的文件描述符

我会假设您没有以正确的模式(即启用写入)打开文件,或者描述符本身可能无效。可能有很多原因,但这看起来不像是操作系统特定的问题,除非你在做一些奇怪的事情。

您可以通过以下方式阅读更多相关信息man 2 open

于 2013-12-30T08:01:41.927 回答
0

这是 iOS6 下的 NSFileHandle 问题。即使在一个空项目中,只要在 iOS6 下使用这个简单的代码,你就可以很容易地崩溃:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    NSFileHandle *fileHandle = [NSFileHandle fileHandleWithStandardError];
    NSData *data = [@"testMessage\n" dataUsingEncoding:NSUTF8StringEncoding];
    NSLog(@"before:%@", fileHandle);
    [fileHandle writeData:data];
    NSLog(@"after:%@", fileHandle);
    return YES;
}

在任何 iOS 下通过 Xcode 进行调试时,此代码在模拟器和设备上都能正常工作。但是,如果您在 iOS6 下不使用 Xcode 运行该应用程序,只需点击设备上的应用程序图标,该应用程序就会崩溃,并显示您在该行中描述的相同错误消息:

[fileHandle writeData:data];

如果在 iOS6 下未附加 Xcode 以进行调试,则似乎 stdout 和 stderr 管道已损坏。

我在 iOS 6.1.3 下检查了这个。

就我而言,该应用程序使用了仅在调试中使用且未在发布中使用的 LogWriter。所以,我可以建议在这种情况下使用 try/catch。它允许您在 iOS6 下的设备上运行调试版本而不会崩溃:

@try
{
    [fileHandle writeData:data];
}
@catch (NSException *e)
{
    NSLog(@"NSException:%@", e);
}
于 2014-09-19T16:47:26.433 回答