本文介绍了从XCode访问Mac上的localhost? Phonegap与Ajax通信到本地Rails应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种方法可以在iPhone设备上通过Phonegap运行的HTML文件中访问 http:// localhost:3000 / posts 模拟器),在XCode?

如果我在Phonegap有一个HTML5应用程序,我只能访问外部样式表与 file:当我在iPhone / iPad上测试它时,用户/ etc .. http:// ... 如果我运行模拟器,我可以访问localhost没有问题。



有办法解决这个问题吗?我知道我可以通过执行 http://username.local/posts 从Parallels运行Windows的Mac上访问localhost,是否有像iOS这样的开发? p>

解决方案

localhost总是指向IPv4中的 127.0.0.1 当前设备的环回网络接口。如果你从你的iPhone打开localhost,它将指向iPhone本身。



但是,如果你在与Mac相同的网络,您的Mac的IP地址,例如 http://192.168.0.20:3000/posts 。您可以在Mac的网络设置中查看您当前的IP地址。



此外,根据您的网络配置,使用Bonjour名称也可能工作。例如: http://mymac.local:3000 / posts 如果您的计算机名称设置为 mymac 在系统首选项共享窗格中。


Is there a way to access http://localhost:3000/posts from within an HTML file that's running through Phonegap for the iPhone on the iPhone device (not the simulator), in XCode?

If I have an HTML5 app in Phonegap, I have only been able to access external stylesheets with file://Users/etc.. or http://... when I'm testing it on the iPhone/iPad itself. If I'm running the simulator, I can access localhost no problem.

Is there a way around this? I know I can access localhost on the Mac from within Parallels running Windows by doing http://username.local/posts, is there something like this for iOS development?

解决方案

"localhost" always points to 127.0.0.1 in IPv4, which is the current device's loopback network interface. If you open "localhost" from your iPhone, it will point to the iPhone itself.

However, if you are in the same network as your Mac, you can simply use your Mac's IP address, e.g. http://192.168.0.20:3000/posts. You can see your current IP address in your Mac's Network Settings.

Also, depending on your network configuration, using the Bonjour name might work as well. For example: http://mymac.local:3000/posts if the name of your computer is set to mymac in the system preferences' Sharing pane.

这篇关于从XCode访问Mac上的localhost? Phonegap与Ajax通信到本地Rails应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 23:59