简体   繁体   中英

Using iOS 11 NEHotspotConfiguration capability on a Simulated Device and not just a physical device

I'm using the NEHotspotConfiguration Class in iOS 11 to connect to a known wifi network. This React Native app works fine on a physical device, and I'm able to programatically connect to a network using the NEHotspotConfiguration class on iOS 11. However, when I try and build/run it in a simulator I get the following error that prevents me from even launching the app:

Undefined symbols for architecture x86_64:  
  "_OBJC_CLASS_$_NEHotspotConfiguration", referenced from:  
      objc-class-ref in IOSWifiManager.o  
  "_OBJC_CLASS_$_NEHotspotConfigurationManager", referenced from:  
      objc-class-ref in IOSWifiManager.o  
ld: symbol(s) not found for architecture x86_64  
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Is there a way to keep using the Simulator to test the rest of my app with this capability enabled, even though I wouldn't be able to use the capability to change the wifi in the Simulator?

There may be other options, but I found the following potential answer in the comments of a medium article that led me to one solution:
https://medium.com/@ercp42/i-got-this-error-ceacd08191b3
"For anyone who experiences the same issue, I fixed it by wrapping the NetworkExtension import and the code where it's used with #if !TARGET_IPHONE_SIMULATOR to side step this issue."

It was a bit more than that, at least for me, though.
I did indeed wrap the @implementation IOSWifiManager implementation in the IOSWifiManager.m file with an #if TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR and left a much simpler else statement to build it on the simulator:

#else

@implementation IOSWifiManager  
RCT_EXPORT_MODULE();  
@end

#endif

I also went into build settings and under Linking Other Linker Flags changed the values for the iOS Simulator and Any Architecture to the following:

"OTHER_LDFLAGS[arch=*]" = (
    "$(inherited)",
    "-ObjC",
    "-lc++",
    "-framework",
    NetworkExtension,
);
    "OTHER_LDFLAGS[sdk=iphonesimulator*]" = (
    "$(inherited)",
    "-ObjC",
    "-lc++",
);

Finally, I changed the Network Extension Framework from being required to being optional and made sure that we were supporting the right build architectures. Hopefully that helps anyone who runs into the same issue!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM