Sie haben die socketio Gastgeber für die „ExternalHosts“ -Taste in PhoneGap hinzuzufügen. plist.
Siehe Faq:
Q. Links to and imported files from external hosts don't load?
A. The latest code has the new white-list feature. If you are referencing external hosts, you will have to add the host in PhoneGap.plist under the "ExternalHosts" key. Wildcards are ok. So if you are connecting to " http://phonegap.com ", you have to add "phonegap.com" to the list (or use the wildcard "*.phonegap.com" which will match subdomains as well). (Note: If you open the plist file in Xcode, you won't need to fiddle with the XML syntax.)
für Android Sie cordova.xml zu bearbeiten haben, und fügen Sie den Zugang zum socketio host:
<access origin="HOST*"/>
index.html (mit socketio Beispiel):
...
<script src="HOST/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('HOST');
socket.on('news', function (data) {
socket.emit('my other event', { my: 'data' });
});
</script>
...
app.js (Server-Seite Javascript/Grund socketio Beispiel):
var io = require('socket.io').listen(80);
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
Die HOST Sie haben mit Hostnamen Ihres socket.io Server ersetzen!
Ist das nur Android? Ich baue für iOS und habe keine cordova.xml, nur eine cordova.plist. Hast du das unter iOS gemacht? Vielen Dank! – fancy
Ja (cordova.xml ist nur android). Für iOS müssen Sie den HOST in PhoneGap.plist (siehe http: // stackoverflow.com/a/8972890/584545) –
Hinzufügen eines Hosts zu der Whitelist tut nichts, was das Setzen des Orgin betrifft, was das Problem ist. Shazron, unten (wer PhoneGap erstellt) hat die richtige Idee, ich weiß einfach nicht wie ich das machen soll. – fancy