Skip to content

Commit c47049a

Browse files
committed
fix: ios not connecting to devtools
1 parent 789e8c6 commit c47049a

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

index.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,37 @@ function getServerIpAddress(host, port) {
2323
}
2424
}
2525

26-
// ios or android device use `localhost`
27-
return `localhost:${port}`
26+
// ios simulator uses localhost
27+
return `127.0.0.1:${port}`
2828
}
2929

3030
module.exports = function install(Vue, {debug = false, host = null, port = 8098} = {}) {
3131
const startApp = Vue.prototype.$start
3232

3333
Vue.prototype.$start = function () {
34-
devtools.connect('ws://localhost', port, {
35-
app: this,
36-
showToast: (message) => require('nativescript-toast').makeText(message).show(),
37-
io() {
38-
const address = `http://${getServerIpAddress(host, port)}`
39-
const SocketIO = require('nativescript-socket.io')
40-
debug && SocketIO.enableDebug()
41-
42-
return SocketIO.connect(address)
43-
}
44-
})
45-
46-
devtools.init(Vue);
34+
const setupDevtools = () => {
35+
devtools.connect('ws://localhost', port, {
36+
app: this,
37+
showToast: (message) => require('nativescript-toast').makeText(message).show(),
38+
io() {
39+
const address = `http://${getServerIpAddress(host, port)}`
40+
const SocketIO = require('nativescript-socket.io')
41+
debug && SocketIO.enableDebug()
42+
return SocketIO.connect(address)
43+
}
44+
})
45+
46+
devtools.init(Vue);
47+
}
48+
49+
if(isAndroid) {
50+
setupDevtools()
51+
} else {
52+
// on ios we need to delay the call because the socket connection is not established
53+
// if called too early in the application startup process
54+
// we might need to add a delay to the setTimeout in the future
55+
setTimeout(setupDevtools)
56+
}
4757

4858
return startApp.call(this)
4959
}

0 commit comments

Comments
 (0)