Question

I'm using this as the observer:

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
      selector:@selector(newConnection:)
       name:NSFileHandleConnectionAcceptedNotification
         object:nil];

This does get called though when it does the app crashes with this message

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CALayerArray newConnection:]: unrecognized selector sent to instance 0x76aed70'

This is the newConnection handler which is currently empty:

- (void)newConnection:(NSNotification*)notification
{
}

It is also declared in the .h file correctly...

this is the code which is calling the notification

 socketPort = [[NSSocketPort alloc] initWithTCPPort:portNumber];
    int fd = [socketPort socket];
    fileHandle = [[NSFileHandle alloc] initWithFileDescriptor:fd
                                    closeOnDealloc:YES];
...
[fileHandle acceptConnectionInBackgroundAndNotify];

edit: the whole thing above is in a class I've made. Everything except the newConnection is inside this function:

- (id)initWithPortNumber:(int)pn delegate:(id)dl
{
if( self = [super init] ) {
...
}

And I called this file in the viewController like this:

    SimpleHTTPServer *server= [[SimpleHTTPServer alloc]initWithPortNumber:80 delegate:self];

Solution:
The problem was: the view was dealloced because of the arc system
the [fileHandle acceptConnectionInBackgroundAndNotify]; Wasn't really a loop that arc detected to it treated the view as idle and automatically dealloced it so I just made a small timer running with a loop every second that leads to an empty method. Which fixed it.

Was it helpful?

Solution 2

The problem was: the view was dealloced because of the arc system the [fileHandle acceptConnectionInBackgroundAndNotify]; Wasn't really a loop that arc detected to it treated the view as idle and automatically dealloced it so I just made a small timer running with a loop every second that leads to an empty method. Which fixed it.

OTHER TIPS

It's telling you exactly what the error is: 'NSInvalidArgumentException', reason: '-[CALayerArray newConnection:]: unrecognized selector sent to instance 0x76aed70'.

The question you need to ask is "why is the object at 0x76aed70 a CALayerArray?"

Start by covering the basics. Set a breakpoint at the addObserver:…, make sure self is what you think it is. Then set a track that pointer so the debugger will break when it's value is changed. You should be able to track this down quickly.

My guess is your object has been deallocated and you didn't remove the observer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top