Issue with PHILIPS HUE APPLE SDK
Asked Answered
W

2

10

I have just written Five lines of code and the app crashes. I check many times but i am unable to track the bug in code.

I Have added the framework..No warnings No Errors but why the damn app crashes:

#import "ViewController.h"
#import <HueSDK_iOS/HueSDK.h>

@interface ViewController ()

@property (strong, nonatomic) PHHueSDK *phHueSDK;
@property (nonatomic, strong) PHBridgeSearching *bridgeSearch;

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  self.phHueSDK = [[PHHueSDK alloc] init]; //Line 1

  [self.phHueSDK enableLogging:YES]; //Line 2

  [self.phHueSDK startUpSDK]; //Line 3

  self.bridgeSearch = [[PHBridgeSearching alloc] initWithUpnpSearch:YES andPortalSearch:YES andIpAdressSearch:YES]; //Line 4

// Start search for bridges
[self.bridgeSearch startSearchWithCompletionHandler:^(NSDictionary *bridgesFound) {
    // Search is complete, handle results (dictionary contains IP and mac addresses of bridges found)
}]; Line 5

}
@end

Crash log as...

2015-04-23 17:15:58.750 FreshHUE[8298:161234] -[__NSCFString objectFromJSONString]: unrecognized selector sent to instance 0x7fb9fa547d60
2015-04-23 17:15:58.849 FreshHUE[8298:161234] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectFromJSONString]: unrecognized selector sent to instance 0x7fb9fa547d60'
*** First throw call stack:
(
        0   CoreFoundation                      0x0000000106512c65 __exceptionPreprocess + 165
        1   libobjc.A.dylib                     0x00000001061a9bb7 objc_exception_throw + 45
        2   CoreFoundation                      0x000000010651a0ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
        3   CoreFoundation                      0x000000010647013c ___forwarding___ + 988
        4   CoreFoundation                      0x000000010646fcd8 _CF_forwarding_prep_0 + 120
        5   FreshHUE                            0x0000000105c01cdd __38-[PHBridgeSearching startPortalSearch]_block_invoke + 332
        6   FreshHUE                            0x0000000105c006ac -[PHHttpRequester connectionDidFinishLoading:] + 101
        7   CFNetwork                           0x000000010859c0bc __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 69
        8   CFNetwork                           0x000000010859c060 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 199
        9   CFNetwork                           0x000000010859c1c7 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 48
        10  CFNetwork                           0x000000010846b757 ___ZN27URLConnectionClient_Classic26_delegate_didFinishLoadingEU13block_pointerFvvE_block_invoke + 107
        11  CFNetwork                           0x0000000108538de1 ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 273
        12  CFNetwork                           0x0000000108456a26 _ZN19RunloopBlockContext13_invoke_blockEPKvPv + 72
        13  CoreFoundation                      0x0000000106419354 CFArrayApplyFunction + 68
        14  CFNetwork                           0x00000001084568e7 _ZN19RunloopBlockContext7performEv + 133
        15  CFNetwork                           0x0000000108456726 _ZN17MultiplexerSource7performEv + 256
        16  CFNetwork                           0x000000010845653c _ZN17MultiplexerSource8_performEPv + 72
        17  CoreFoundation                      0x0000000106446431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
        18  CoreFoundation                      0x000000010643c2fd __CFRunLoopDoSources0 + 269
        19  CoreFoundation                      0x000000010643b934 __CFRunLoopRun + 868
        20  CoreFoundation                      0x000000010643b366 CFRunLoopRunSpecific + 470
        21  Foundation                          0x0000000105d5ef92 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 275
        22  FreshHUE                            0x0000000105c00fc7 __32-[PHBridgeSearching startSearch]_block_invoke + 253
        23  libdispatch.dylib                   0x0000000108cd0186 _dispatch_call_block_and_release + 12
        24  libdispatch.dylib                   0x0000000108cef614 _dispatch_client_callout + 8
        25  libdispatch.dylib                   0x0000000108cd9552 _dispatch_root_queue_drain + 1768
        26  libdispatch.dylib                   0x0000000108cdab17 _dispatch_worker_thread3 + 111
        27  libsystem_pthread.dylib             0x00000001090746cb _pthread_wqthread + 729
        28  libsystem_pthread.dylib             0x00000001090724a1 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

UPDATE TO QUESTION

when i change line 4 to (Set portal search to no)my app runs fine..But I want Portal Search and why is this happening

self.bridgeSearch = [[PHBridgeSearching alloc] initWithUpnpSearch:YES andPortalSearch:NO andIpAdressSearch:YES]; //Line 4
Warila answered 23/4, 2015 at 11:48 Comment(2)
There's no crash point in above code. show that completionHandler block. I think error is there.Merrygoround
there is nothing in completion block...i have written this much code onlyWarila
W
11

After spending whole night in the sample app provided by PHILIPS i am able to locate the error.

In the official documentation of PHILIPS HUE they haven't mention that we have to add -ObjC linker flag

Adding -ObjC linker Flag Solved My Problem

Warila answered 28/4, 2015 at 5:45 Comment(0)
B
1

Question

I am getting an unrecognized selector when using the Phillips Hue IOS Stack. Can anyone assist with this?

2015-04-23 17:15:58.750 FreshHUE[8298:161234] -[__NSCFString objectFromJSONString]: unrecognized selector sent to instance 0x7fb9fa547d60
2015-04-23 17:15:58.849 FreshHUE[8298:161234] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectFromJSONString]: unrecognized selector sent to instance 0x7fb9fa547d60'
*** First throw call stack:
(
        0   CoreFoundation                      0x0000000106512c65 __exceptionPreprocess + 165
        1   libobjc.A.dylib                     0x00000001061a9bb7 objc_exception_throw + 45
        2   CoreFoundation                      0x000000010651a0ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
        3   CoreFoundation                      0x000000010647013c ___forwarding___ + 988
        4   CoreFoundation                      0x000000010646fcd8 _CF_forwarding_prep_0 + 120
        5   FreshHUE                            0x0000000105c01cdd __38-[PHBridgeSearching startPortalSearch]_block_invoke + 332
        6   FreshHUE                            0x0000000105c006ac -[PHHttpRequester connectionDidFinishLoading:] + 101
        7   CFNetwork                           0x000000010859c0bc __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 69
        8   CFNetwork                           0x000000010859c060 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 199
        9   CFNetwork                           0x000000010859c1c7 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 48
        10  CFNetwork                           0x000000010846b757 ___ZN27URLConnectionClient_Classic26_delegate_didFinishLoadingEU13block_pointerFvvE_block_invoke + 107
        11  CFNetwork                           0x0000000108538de1 ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 273
        12  CFNetwork                           0x0000000108456a26 _ZN19RunloopBlockContext13_invoke_blockEPKvPv + 72
        13  CoreFoundation                      0x0000000106419354 CFArrayApplyFunction + 68
        14  CFNetwork                           0x00000001084568e7 _ZN19RunloopBlockContext7performEv + 133
        15  CFNetwork                           0x0000000108456726 _ZN17MultiplexerSource7performEv + 256
        16  CFNetwork                           0x000000010845653c _ZN17MultiplexerSource8_performEPv + 72
        17  CoreFoundation                      0x0000000106446431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
        18  CoreFoundation                      0x000000010643c2fd __CFRunLoopDoSources0 + 269
        19  CoreFoundation                      0x000000010643b934 __CFRunLoopRun + 868
        20  CoreFoundation                      0x000000010643b366 CFRunLoopRunSpecific + 470
        21  Foundation                          0x0000000105d5ef92 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 275
        22  FreshHUE                            0x0000000105c00fc7 __32-[PHBridgeSearching startSearch]_block_invoke + 253
        23  libdispatch.dylib                   0x0000000108cd0186 _dispatch_call_block_and_release + 12
        24  libdispatch.dylib                   0x0000000108cef614 _dispatch_client_callout + 8
        25  libdispatch.dylib                   0x0000000108cd9552 _dispatch_root_queue_drain + 1768
        26  libdispatch.dylib                   0x0000000108cdab17 _dispatch_worker_thread3 + 111
        27  libsystem_pthread.dylib             0x00000001090746cb _pthread_wqthread + 729
        28  libsystem_pthread.dylib             0x00000001090724a1 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

Answer

In most cases, the answer is related to the information in the reason code. For this instance the reason stated is:

 '-[__NSCFString objectFromJSONString]: unrecognized selector sent to instance 0x7fb9fa547d60'

Which is not immediately called by your code. In this case I believe it may be happening because your event lifecycle is incorrect. I notice your pattern differs from the one shown in the sample app. I think you need to swap lines 2 and 3. You are attempting to set a property on the SDK before you start it up.

I would also move the entire SDK startup sequence to the App Delegate class, in case there are any race conditions happening internally. The two lines that you use for the search seem to be inline with the QuickStart sample app. You could also try running the sample app to see if there are any issues on your system or it might even be a bug in the repo. Try adjusting the architecture as noted above and it should further isolate the issue.

UPDATE:

The comment seems to support the conclusion that there might be an internal race condition happening in the SDK. I suggest moving the property and first three lines as noted to the AppDelegate and see if that will work when the portalSearch is set to YES.

Buff answered 23/4, 2015 at 12:24 Comment(8)
i followed the sequence from here..developers.meethue.com/documentation/apple-api-guideWarila
and when in set portalSearch to NO .. then my code works fineWarila
I swapped the lines but nothing happens..and the sample app works fine on my systemWarila
@RahulMishra Just curious if you get different results by moving the SDK logic to the AppDelegate?Buff
same thing happens when i write my code to app delegateWarila
app still crashes in AppDelegateWarila
@RahulMishra - You've moved just the startup portion to the AppDelegate. The Search is still in the view controller, right? I'd take a closer look at that sample in the repo and mimic that as much as possible.Buff
C I had moved my all code to AppDelegate... I you want to see the code i can share it with youWarila

© 2022 - 2024 — McMap. All rights reserved.