简体   繁体   English

在模拟设备上而不只是物理设备上使用iOS 11 NEHotspotConfiguration功能

[英]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. 我正在使用iOS 11中的NEHotspotConfiguration类连接到已知的wifi网络。 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: 这个React Native应用程序在物理设备上可以正常工作,并且我可以使用iOS 11上的NEHotspotConfiguration类以编程方式连接到网络。但是,当我尝试在模拟器中构建/运行它时,出现以下错误,该错误可以防止我什至没有启动该应用程序:

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? 即使我无法使用该功能来更改模拟器中的wifi,是否有办法继续使用模拟器来测试我的应用程序的其余部分并启用此功能?

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 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." “对于遇到相同问题的任何人,我都通过将NetworkExtension导入及其与#if!TARGET_IPHONE_SIMULATOR一起使用的代码进行包装来解决此问题,从而解决了该问题。”

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: 我确实使用#if TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR@implementation IOSWifiManager实现包装在IOSWifiManager.m文件中,并留下了一个简单得多的else语句在模拟器上构建它:

#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: 我还进入了构建设置,并在“链接其他链接器标志”下将“ iOS模拟器”和“任何体系结构”的值更改为以下值:

"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! 希望能对遇到同样问题的任何人有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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