ionic-cli icon indicating copy to clipboard operation
ionic-cli copied to clipboard

ionic emulate --livereload ios not working after latest Apple updates

Open mirkonasato opened this issue 11 years ago • 55 comments

See http://forum.ionicframework.com/t/live-reload-error-failed-to-load-webpage-with-error/32831/4

mirkonasato avatar Oct 05 '15 20:10 mirkonasato

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.

kylefox avatar Oct 05 '15 21:10 kylefox

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.

mirkonasato avatar Oct 05 '15 21:10 mirkonasato

+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

eroh92 avatar Oct 07 '15 06:10 eroh92

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.

eroh92 avatar Oct 07 '15 14:10 eroh92

+1

mattchue avatar Oct 07 '15 18:10 mattchue

+1

reapp3r avatar Oct 08 '15 07:10 reapp3r

+1

johnrobertcobbold avatar Oct 08 '15 08:10 johnrobertcobbold

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 avatar Oct 09 '15 20:10 jimmyhsu

@jimmyhsu that isn't the problem. I have that added and it still didn't work for me until I changed to localhost.

bentomas avatar Oct 09 '15 21:10 bentomas

@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.

kylefox avatar Oct 09 '15 21:10 kylefox

@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.

jimmyhsu avatar Oct 09 '15 21:10 jimmyhsu

+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.

buunguyen avatar Oct 10 '15 05:10 buunguyen

I had also previously fixed the NSAppTransportSecurity issues by applying the plist fix. Stopped working since I upgraded to El Capitan

johnrobertcobbold avatar Oct 10 '15 05:10 johnrobertcobbold

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.

mattchue avatar Oct 12 '15 20:10 mattchue

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.

  1. ionic start tmp && cd tmp

  2. npm install cordova-config-utils && chmod +x hooks/after_prepare/011_update_config.js

  • (need to fix permission error)
  1. add the following to the config.xml
    <config-file platform="ios" target="*-Info.plist" parent="NSAppTransportSecurity">
      <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
      </dict>
    </config-file>
  1. 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 avatar Oct 13 '15 16:10 mhartington

@mhartington Did you try with the --emulator flag instead of --device ?

kylefox avatar Oct 13 '15 16:10 kylefox

I definitely had app transport security disabled when I tested it - using this template: https://github.com/mirkonasato/ionic-starter-blank

mirkonasato avatar Oct 13 '15 17:10 mirkonasato

In fact, without disabling ATS the localhost workaround didn't work either.

mirkonasato avatar Oct 13 '15 17:10 mirkonasato

Hmm, weird that it happens with the sim...but not the actual device...

mhartington avatar Oct 13 '15 19:10 mhartington

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

mirkonasato avatar Oct 13 '15 19:10 mirkonasato