【问题标题】:Using iOS 11 NEHotspotConfiguration capability on a Simulated Device and not just a physical device在模拟设备上使用 iOS 11 NEHotspotConfiguration 功能,而不仅仅是物理设备
【发布时间】:2018-10-27 02:06:33
【问题描述】:

我正在使用 iOS 11 中的 NEHotspotConfiguration 类连接到已知的 wifi 网络。这个 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)

是否有办法在启用此功能的情况下继续使用模拟器来测试我的应用程序的其余部分,即使我无法使用该功能更改模拟器中的 wifi?

【问题讨论】:

标签: ios xcode react-native ios-simulator


【解决方案1】:

可能还有其他选择,但我在一篇中型文章的 cmets 中找到了以下潜在答案,这使我找到了一种解决方案:
https://medium.com/@ercp42/i-got-this-error-ceacd08191b3
“对于遇到相同问题的任何人,我通过包装 NetworkExtension 导入和与 #if !TARGET_IPHONE_SIMULATOR 一起使用的代码来解决此问题。”

不过,至少对我来说还不止这些。
我确实用#if TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR@implementation IOSWifiManager 实现包装在IOSWifiManager.m 文件中,并留下了一个更简单的else 语句来在模拟器上构建它:

#else

@implementation IOSWifiManager  
RCT_EXPORT_MODULE();  
@end

#endif

我还进入了构建设置,在 Linking Other Linker Flags 下将 iOS Simulator 和 Any Architecture 的值更改为以下内容:

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

最后,我将网络扩展框架从必需更改为可选,并确保我们支持正确的构建架构。希望对遇到同样问题的人有所帮助!

【讨论】:

    猜你喜欢
    • 2017-07-29
    • 2018-07-04
    • 1970-01-01
    • 1970-01-01
    • 2021-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-20
    相关资源
    最近更新 更多