ionic emulate --livereload ios not working after latest Apple updates
See http://forum.ionicframework.com/t/live-reload-error-failed-to-load-webpage-with-error/32831/4
I can confirm this exact error. It seems something has changed in iOS9 that prevents the simulator from accessing IP addresses on the local network. Connecting to localhost still works, however.
If I run a simple HTTP server from my Mac, I am able to access it using Safari in the iOS simulator at localhost:8000. However, I'm not able to access it at 10.0.1.10:8000 (my local network IP). In fact, Safari shows me the same error (verbatim) that appears in the Ionic logs: "The operation couldn’t be completed. No such file or directory"
I suspect it would work if ionic emulate were modified to accept the same [--all|-a] Have the server listen on all addresses (0.0.0.0) flag that ionic serve provides.
From my investigation (see forum thread) seems like a solution would actually be for ionic emulate to simply pass localhost:8100 as the initial page to load since that works fine in the iOS Simulator, instead of trying to determine the IP from the network interface.
The dev server is listening fine, it's just the Simulator that has no access to the local network. But can see localhost.
+1 localhost appears to work. You can even see this hitting localhost:8100 and localhost:35729 in mobile safari, while loading these pages on the same ports, but full ip address (i.e 10.x.x.x) still gives the same error I see in the xcode logs: Failed to load webpage with error: The operation couldn’t be completed. No such file or directory
One workaround I found is to run Charles Proxy. It works because it just proxies those same network calls that are being blocked, back to your local machine.
+1
+1
+1
Apple's new network transport security rules are the main culprit.
Adding
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
to your *-Info.plist solves most of the issues, but if you specify them separately you will have to manually add it yourself. I would look into automating this process as well.
A would wager that lot of users haven't encountered this issue as many have added the above code for iOS 9.
@jimmyhsu that isn't the problem. I have that added and it still didn't work for me until I changed to localhost.
@jimmyhsu @bentomas Yep, separate issue as far as I can tell. Even with the NSAppTransportSecurity patch the simulator is unable to access IP addresses on the local network.
@bentomas @kylefox Ahh, when I ran the app via xcode it told me the livereload address in the logs that it was blocked due to being HTTP.
A different bug I am getting is $ ionic address doesn't set the attributes correctly, and only refuses to set the address to localhost for me.
+1. Pretty sure it's not related to NSAppTransportSecurity as I have it set in the plist but still have the error when live-reload is enabled. Running without live reload works. In the mean time, I'm working around by using iOS 8 simulator.
I had also previously fixed the NSAppTransportSecurity issues by applying the plist fix. Stopped working since I upgraded to El Capitan
For what it's worth with regards to finding the cause, I did get it working with @eroh92's suggestion. Starting Charles made --livereload work immediately.
So far, I have been able to isolate this as an issue with apples new ATS setup. @kylefox mentioned not being able to use live-reload with ATS setup, but I have been able to set up live-reload over IP and have it work fine.
My steps to get everything working fine.
-
ionic start tmp && cd tmp
-
npm install cordova-config-utils && chmod +x hooks/after_prepare/011_update_config.js
- (need to fix permission error)
- add the following to the config.xml
<config-file platform="ios" target="*-Info.plist" parent="NSAppTransportSecurity">
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</config-file>
- ionic run ios --device -lc
With that, I was able to get live reload working without any issues. Even went back to make sure that the live-reload server was setup for IP.
@mhartington Did you try with the --emulator flag instead of --device ?
I definitely had app transport security disabled when I tested it - using this template: https://github.com/mirkonasato/ionic-starter-blank
In fact, without disabling ATS the localhost workaround didn't work either.
Hmm, weird that it happens with the sim...but not the actual device...
Yeah it's a weird issue to do with the iOS Simulator and networking. Couldn't find anything in the Apple documentation/release notes to confirm if the new behaviour is expected or not.
Would be great if you could pass an --address option to ionic simulate like you can for ionic serve so at least you can do ionic emulate -lc --address localhost ios.
My versions:
$ ionic info
Your system information:
Cordova CLI: 5.3.3
Gulp version: CLI version 3.9.0
Gulp local:
Ionic Version: 1.1.0
Ionic CLI Version: 1.7.0
Ionic App Lib Version: 0.5.1-beta.0
ios-deploy version: 1.8.2
ios-sim version: 5.0.2
OS: Mac OS X El Capitan
Node Version: v0.12.7
Xcode version: Xcode 7.0.1 Build version 7A1001