PhilipsHue / PhilipsHueSDK-iOS-OSX

The Software Development Kit for Philips Hue on iOS and OS X (beta)
579 stars 169 forks source link

Crash After Initial Pushlink #89

Closed tanner0101 closed 7 years ago

tanner0101 commented 9 years ago

I'm using Swift with the Hue SDK and I'm experiencing a crash right after the first push link. My code is almost exactly what appears in the sample app, except translated to Swift.

The authentication is successful and a couple of "local connection" heart beat messages are received. But after 3 or 4 the app crashes. Sometimes yielding an error message saying allResourcesHeartbeatFiredLocal unrecognized sender sent to instance or other times saying [PHSchedulerTask exectue] [PHScheduler executeNextTask]

screen shot 2015-03-30 at 8 15 35 pm

tanner0101 commented 9 years ago

2015-03-30 20:43:23.326 Glow[6687:610635] -[DDLoggerNode allResourcesHeartbeatFiredLocal]: unrecognized selector sent to instance 0x7f8a48e2f690 2015-03-30 20:43:23.336 Glow[6687:610635] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DDLoggerNode allResourcesHeartbeatFiredLocal]: unrecognized selector sent to instance 0x7f8a48e2f690'

Just happened randomly–not after push link.

philwebster commented 9 years ago

Hey Tanner, I just ran into this issue myself. From what I can tell, whenever you create an sdk instance, you also need to set up a PHNotificationManager and register it for three notifications:

PHNotificationManager *notificationManager = [PHNotificationManager defaultManager];
[notificationManager registerObject:self withSelector:@selector(localConnection) forNotification:LOCAL_CONNECTION_NOTIFICATION];
[notificationManager registerObject:self withSelector:@selector(noLocalConnection) forNotification:NO_LOCAL_CONNECTION_NOTIFICATION];
[notificationManager registerObject:self withSelector:@selector(notAuthenticated) forNotification:NO_LOCAL_AUTHENTICATION_NOTIFICATION];

Note that you can create a method that does nothing and register that for the notifications, although you probably want to handle them properly.

philwebster commented 9 years ago

The above may be incorrect advice. After more crashes, I found that calling startUpSDK multiple times seemed to be causing the problem. Now I'm doing this:

if (!self.sdk.localConnected) {
    [self.sdk startUpSDK];
    [self.sdk enableLocalConnection];
}
tanner0101 commented 9 years ago

Okay, that makes sense. I implemented the !self.sdk.localConnected and it appears to be working.

I was also having issues with some notification handlers not being registered at an earlier point, so maybe that was causing you problems as well.