Vous devez ajouter l'hôte socketio à la touche « ExternalHosts » dans PhoneGap. plist.
Voir 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.)
pour Android vous devez éditer cordova.xml et ajouter l'accès à l'hôte socketio:
<access origin="HOST*"/>
index.html (avec socketio exemple):
...
<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 (côté serveur javascript/Exemple de socketio de base):
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);
});
});
L'hôte vous devez remplacer par le nom d'hôte de votre serveur socket.io!
Est-ce seulement Android? Je construis pour iOS et n'ai pas de cordova.xml, seulement un cordova.plist. Avez-vous fait cela sur iOS? Merci! – fancy
Oui (cordova.xml est uniquement android). Pour iOS, vous devez mettre l'HÔTE dans PhoneGap.plist (voir http: // stackoverflow.com/a/8972890/584545) –
Ajout d'un hôte à la liste blanche ne fait rien pour régler l'orgin, qui est le problème. Shazron, ci-dessous (qui crée PhoneGap) a la bonne idée, je ne sais pas comment faire ça. – fancy