Jansen
Jansen

Reputation: 143

[RCTBatchedBridge perfStats]: unrecognized selector sent to instance

all. When I am Using react native in existing iOS app, I encountered this exception. Did anyone know how to fix it ? the crash stack as follow:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RCTBatchedBridge perfStats]: unrecognized selector sent to instance 0x7fe1195ca680'

*** First throw call stack: (0 CoreFoundation 0x000000010f0bff65 __exceptionPreprocess + 165

1   libobjc.A.dylib                     0x000000010eb39deb objc_exception_throw + 48
2   CoreFoundation                      0x000000010f0c858d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3   CoreFoundation                      0x000000010f015f7a ___forwarding___ + 970
4   CoreFoundation                      0x000000010f015b28 _CF_forwarding_prep_0 + 120
5   ReactNativeTest                     0x000000010e5923ad -[RCTBatchedBridge _mainThreadUpdate:] + 429
6   QuartzCore                          0x000000010fee7864 _ZN2CA7Display15DisplayLinkItem8dispatchEv + 50
7   QuartzCore                          0x000000010fee772e _ZN2CA7Display11DisplayLink14dispatch_itemsEyyy + 418
8   CoreFoundation                      0x000000010f020364 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
9   CoreFoundation                      0x000000010f01ff11 __CFRunLoopDoTimer + 1089
10  CoreFoundation                      0x000000010efe18b1 __CFRunLoopRun + 1937
11  CoreFoundation                      0x000000010efe0e98 CFRunLoopRunSpecific + 488
12  GraphicsServices                    0x0000000113aeead2 GSEventRunModal + 161
13  UIKit                               0x0000000110007676 UIApplicationMain + 171
14  ReactNativeTest                     0x000000010e55615f main + 111
15  libdyld.dylib                       0x00000001122e692d start + 1
16  ???                                 0x0000000000000001 0x0 + 1

) libc++abi.dylib: terminating with uncaught exception of type NSException

Upvotes: 0

Views: 2125

Answers (1)

Jansen
Jansen

Reputation: 143

solution: Build Settings -> other linker flags -> add "-force_load" tag with your path to libReact.a

the reason of this crash is that perfStats a object of RCTPerfStats which is a category of RCTBridge.

@interface RCTBridge (RCTPerfStats)

@property (nonatomic, strong, readonly) RCTPerfStats *perfStats;

@end

RCTBatchedBridge is a subclass of RCTBridge. [RCTBatchedBridge perfStats] called the category method that is implemented in a static library.

However, the objective-c linker complicates things slightly.

"Objective-C does not define linker symbols for methods. Linker symbols are only defined for classes. For example, if main.m includes the code [[FooClass alloc] initWithBar:nil]; then main.o will contain an undefined symbol for FooClass, but no linker symbols for the -initWithBar: method will be in main.o. Since categories are a collection of methods, using a category's method does not generate an undefined symbol. This means the linker does not know to load an object file defining the category, if the class itself is already defined. This causes the same "selector not recognized" runtime exception you would see for any unimplemented method."

https://developer.apple.com/library/mac/qa/qa1490/_index.html

But if your project does not allow you to adopt the -ObjC linker flags, you can try -force_load linker flag. This flag only load the specified library and has little effect on the others.

Upvotes: 2

Related Questions