PHILIPS HUE APPLE SDK 问题
Issue with PHILIPS HUE APPLE SDK
我刚刚编写了 Five
行代码,但应用程序崩溃了。我检查了很多次,但我无法跟踪代码中的错误。
我已经添加了框架..没有警告没有错误但是为什么该死的应用程序崩溃了:
#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
崩溃日志为...
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)
问题更新
当我将第 4 行更改为(将门户搜索设置为否)时,我的应用程序运行良好..但我想要门户搜索以及为什么会这样
self.bridgeSearch = [[PHBridgeSearching alloc] initWithUpnpSearch:YES andPortalSearch:NO andIpAdressSearch:YES]; //Line 4
问题
我在使用 Phillips Hue IOS Stack 时遇到无法识别的选择器。有人可以帮忙吗?
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)
回答
在大多数情况下,答案与原因代码中的信息有关。对于这种情况,说明的原因是:
'-[__NSCFString objectFromJSONString]: unrecognized selector sent to instance 0x7fb9fa547d60'
您的代码不会立即调用它。在这种情况下,我相信它可能正在发生,因为您的事件生命周期不正确。我注意到您的模式与示例应用程序中显示的模式不同。我认为您需要交换第 2 行和第 3 行。您正试图在启动之前在 SDK 上设置 属性。
我还会将整个 SDK 启动序列移至 App Delegate class,以防内部发生任何竞争条件。您用于搜索的两行似乎与 QuickStart 示例应用程序内联。您也可以尝试 运行 示例应用程序,看看您的系统是否有任何问题,或者它甚至可能是 repo 中的错误。尝试如上所述调整架构,它应该会进一步隔离问题。
更新:
该评论似乎支持 SDK 中可能发生内部竞争条件的结论。我建议移动 属性 和前三行,如 AppDelegate 所指出的那样,看看当 portalSearch 设置为 YES 时它是否会起作用。
在 PHILIPS 提供的示例应用程序中花了一整夜后,我找到了错误。
在 PHILIPS HUE 的官方文档中,他们没有提到我们必须添加 -ObjC 链接器标志
添加 -ObjC 链接器标志解决了我的问题
我刚刚编写了 Five
行代码,但应用程序崩溃了。我检查了很多次,但我无法跟踪代码中的错误。
我已经添加了框架..没有警告没有错误但是为什么该死的应用程序崩溃了:
#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
崩溃日志为...
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)
问题更新
当我将第 4 行更改为(将门户搜索设置为否)时,我的应用程序运行良好..但我想要门户搜索以及为什么会这样
self.bridgeSearch = [[PHBridgeSearching alloc] initWithUpnpSearch:YES andPortalSearch:NO andIpAdressSearch:YES]; //Line 4
问题
我在使用 Phillips Hue IOS Stack 时遇到无法识别的选择器。有人可以帮忙吗?
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)
回答
在大多数情况下,答案与原因代码中的信息有关。对于这种情况,说明的原因是:
'-[__NSCFString objectFromJSONString]: unrecognized selector sent to instance 0x7fb9fa547d60'
您的代码不会立即调用它。在这种情况下,我相信它可能正在发生,因为您的事件生命周期不正确。我注意到您的模式与示例应用程序中显示的模式不同。我认为您需要交换第 2 行和第 3 行。您正试图在启动之前在 SDK 上设置 属性。
我还会将整个 SDK 启动序列移至 App Delegate class,以防内部发生任何竞争条件。您用于搜索的两行似乎与 QuickStart 示例应用程序内联。您也可以尝试 运行 示例应用程序,看看您的系统是否有任何问题,或者它甚至可能是 repo 中的错误。尝试如上所述调整架构,它应该会进一步隔离问题。
更新:
该评论似乎支持 SDK 中可能发生内部竞争条件的结论。我建议移动 属性 和前三行,如 AppDelegate 所指出的那样,看看当 portalSearch 设置为 YES 时它是否会起作用。
在 PHILIPS 提供的示例应用程序中花了一整夜后,我找到了错误。
在 PHILIPS HUE 的官方文档中,他们没有提到我们必须添加 -ObjC 链接器标志
添加 -ObjC 链接器标志解决了我的问题