简体   繁体   English

在React Native中获取(或Axios)在iOS应用程序的EXPO中不起作用

[英]Fetch (or Axios) in react native not working for expo for iOS apps

iOS doesn't allow to navigate to http only url, allowing only https. iOS不允许导航到仅HTTP网址,仅允许https。

There is a solution, which is changing some code inside info.plist file 有一个解决方案,它正在更改info.plist文件中的一些代码

https://github.com/facebook/react-native/issues/8717 https://github.com/facebook/react-native/issues/8717

How can I change settings for iOS, as it comes with only .expo folder but nothing else. 我如何更改iOS的设置,因为它仅带有.expo文件夹,而没有其他任何东西。

Do I need to change server configuration for this at last? 最后是否需要为此更改服务器配置? :( :(

As you properly find out, the problem is that iOS do not allow arbitrary calls to non-secure(http only) domains. 如您所知,问题是iOS不允许任意调用非安全(仅http)域。 It was a feature introduced with iOS 9 in order to push developers onto more secured connections. 这是iOS 9引入的一项功能,用于将开发人员推送到更安全的连接上。

As per writing of this(mid 2017), there is workaround. 根据本文的撰写(2017年中),有解决方法。 You should open 你应该打开

{Your-project}/ios/{Your-project}/Info.plist {Your-project} / ios / {Your-project} /Info.plist

and set proper values for the domain you are targeting( docs ). 并为您要定位的域设置适当的值( docs )。

Following example will disable ATS and allow HTTP call to somedomain.com : 以下示例将禁用ATS并允许HTTP调用somedomain.com

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>localhost</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
        </dict>
    </dict>

In your situation, I believe you are looking for the Info.plist file in the wrong place. 根据您的情况,我认为您在错误的位置查找Info.plist文件。 It is not part of the node modules, instead look at the ios path specified above. 它不是节点模块的一部分,而是查看上面指定的ios路径。

Unfortunately Expo doesn't allow you to modify the App Transport Security Settings but may bake in a configuration option. 不幸的是,Expo不允许您修改App Transport Security设置,但可能会烘焙一个配置选项。 Here's a Github thread . 这是Github线程

You can eject from Expo but only do this if you are 100% sure. 您可以从Expo eject ,但只有在100%确信的情况下才能这样做。

This will give you a project very similar to one created by react-native init 这将为您提供一个与react-native init创建的项目非常相似的项目

This features an ios and android directory, navigating to ios/YourProject/ will reveal Info.plist . 这具有一个iosandroid目录,导航到ios/YourProject/将显示Info.plist

How much of a struggle would it be to install an SSL certificate on your server? 在您的服务器上安装SSL证书要付出多少努力? It may be more beneficial to do this and you can use a free service like letsencrypt . 这样做可能会更有益,并且您可以使用letsencrypt之类的免费服务。

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

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