App Crashes on my devices but works fine in simulator and when debugging through xcode

2

my app got crashes when i try to run in IOS6 device..but it working fine in simulator,debugging through xcode and it also run smoothly in IOS 7 device.. the problem is only for IOS 6 device. this is my console history

<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

And this is the my Device Log History...

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
iphone
ios
objective-c
xcode
amazon-s3
asked on Stack Overflow Oct 17, 2013 by pradeep • edited Oct 17, 2013 by pradeep

2 Answers

3

I'm not sure why it would be ios6 specific since the reason it crashes is right there

* -[NSConcreteFileHandle writeData:]: Bad file descriptor

I would assume that you didn't open the file in the correct mode (i.e. with writing enabled) or maybe the descriptor itself is invalid. There could be many reasons but this doesn't look like an OS specific issue unless you're doing something weird.

You can read more about this by doing man 2 open

answered on Stack Overflow Dec 30, 2013 by evanescent
0

It is NSFileHandle issue under iOS6. You can easily get a crash just using this simple code under iOS6 even in an empty project:

- (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;
}

This code works properly on simulator and on device when debugging through Xcode under any iOS. But, if you run the app without Xcode under iOS6, just tap on app icon on device, this app crashes with the same error message that you describes on the line:

[fileHandle writeData:data];

It looks like stdout and stderr pipelines are broken if Xcode is not attached under iOS6 for debug.

I checked this under iOS 6.1.3.

In my case the app used LogWriter that used only in debug and was not used in release. So, I can suggest using try/catch in this case. It allows you to run debug version on device under iOS6 without crashes:

@try
{
    [fileHandle writeData:data];
}
@catch (NSException *e)
{
    NSLog(@"NSException:%@", e);
}
answered on Stack Overflow Sep 19, 2014 by slamor • edited Sep 19, 2014 by slamor

User contributions licensed under CC BY-SA 3.0