首页 > 解决方案 > Xcode ios react 应用程序仅阻止进入模拟器

问题描述

我有一个在反应中创建的 ios 应用程序,当我在控制台 ionic serve 中运行时一切正常,当我将应用程序运行到模拟器中时,应用程序在 Axios 请求上被阻止。

const sendGetRequest = () => {

  return axios({
    url: "https://example.com/wp-json/survey/v1/listOfQuestions",
    method: 'get'
    
  }).then(response => {
    var  answerQuestionsFirstTimeCounting = [];
    for (let index = 1; index <= response.data.length; index++) {
      if(response.data[index] != undefined) {
        var categoryName =response.data[index].category.toLowerCase();
        //categoryName = categoryName.replaceAll(" ", "_");
        var search = ' ';
        var replaceWith = '_';

        categoryName = categoryName.split(search).join(replaceWith);
        if(!questionsCategories.includes(categoryName)) {
          questionsCategories.push(categoryName);
        }
      }
      answerQuestionsFirstTimeCounting[index] = 0; 
    }
    
    nrQuestions = response.data.length;
  
    return response.data;
  })
};

我无法看到有关此错误的一些日志详细信息。相同的代码正在应用程序 android 上运行。

更有Xcode经验的人可以帮我告诉我,我可以在哪里调试,看看问题出在哪里?

更新:

我已经使用 proxyman 工具来跟踪请求,但我有这个错误:

在此处输入图像描述

交叉源没问题,我在服务器上设置了分配来自everywere 的请求

<IfModule mod_headers.c>
  Header set Access-Control-Allow-Origin "*"

ssl 证书正常是绿色的 另一台服务器上的相同 API 正在工作,但此服务器没有。我不知道问题出在哪里,为什么请求仅在 ios 模拟器和真实设备中被拒绝。

任何想法或建议将不胜感激

标签: iosreactjstypescriptxcode

解决方案


推荐阅读