RN0.30.0+不需要修改IP地址
Xcode 打印
Jan 11 17:47:48 AwesomeProject[5347] <Error>: CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Jan 11 17:47:48 AwesomeProject[5347] <Error>: CGContextTranslateCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Jan 11 17:47:48 AwesomeProject[5347] <Error>: CGContextRestoreGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2016-01-11 17:47:48.725 [error][tid:main] Could not connect to development server.
Ensure the following:
- Node server is running and available on the same network - run 'npm start' from react-native root
- Node server URL is correctly set in AppDelegate
URL: http://localhost:8081/index.ios.bundle?platform=ios&dev=true
解決:
在AppDelegate.m
文件中,把一下代碼中的localhost
改為你電腦的IP地址锹淌,并且保證連接的是同一個(gè)網(wǎng)絡(luò)(例如:連接同一個(gè)路由的網(wǎng)絡(luò))庆寺。
jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];
也許你會(huì)遇到另外一個(gè)問(wèn)題
WebSocket connection failed with error Error Domain=NSPOSIXErrorDomain Code=61 "Connection refused"
請(qǐng)?zhí)D(zhuǎn)到http://www.reibang.com/p/2c5e738cecca 查看(因?yàn)楸救诉@兩個(gè)問(wèn)題不是同時(shí)出現(xiàn),所以分開(kāi)寫(xiě))垢村。
參考
Running On Device
Test your React Native app on your iPhone or iPad