Jim Bennett
Xamarin MVP Microsoft MVP

Mobile developer at EROAD, Xamarin MVP and Certified Developer, Microsoft MVP, author of Xamarin In Action, blogger, speaker, father and lover of beer, whisky and Thai food. Opinions are my own.

  Auckland, New Zealand
See me soon at:
NDC Sydney 2017
Xamarin In Action
  Xamarin In Action
  Twitter
  GitHub
  LinkedIn
  YouTube
  Email
  CV

I keep getting an annoying issue with my iOS simulators. When I run an app in a simulator that needs any form of network connection I get a dialog box popup from the built in Mac firewall asking if I want to allow incoming connections. Even though I click 'allow', I get asked this every time and it's getting tedious.

Firewall request from the simulator

The issue seems to be in the firewall. When I allow an iOS app it permits the app to access the network, but the iOS simulator does not seem to have permissions. The firewall gets confused - the simulator doesn't have permissions so the network request is blocked pending approval from me, but the firewall doesn't 'see' the simulator, instead it sees the iOS app and gives that permission.

The problems comes from Xcode, it should set the firewall permissions when you install it but sometimes it fails. There is an easy fix - I've got a script that opens up the firewall to the simulator. It turns the firewall off (so make sure you are disconnected from the internet or not anywhere dodgy), enables Xcode and the iOS simulator as a firewall exception, then turns it back on.

#temporarily shut firewall off:
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate off

#put Xcode as an exception:
/usr/libexec/ApplicationFirewall/socketfilterfw --add /Applications/Xcode.app/Contents/MacOS/Xcode

#put iOS Simulator as an exception:
/usr/libexec/ApplicationFirewall/socketfilterfw --add /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator

#re-enable firewall:
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate on  

Run this, give it your password as it needs sudo access and bingo, problem goes away. You may need to run this every time Xcode is updated though...




About the Author

Jim Bennett

International C# and Xamarin geek - Microsoft MVP, Xamarin MVP and Certified Developer, blogger, speaker, father and lover of beer, whisky and Thai food

 

I keep getting an annoying issue with my iOS simulators. When I run an app in a simulator that needs any form of network connection I get a dialog box popup from the built in Mac firewall asking if I want to allow incoming connections. Even though I click 'allow', I get asked this every time and it's getting tedious.

Firewall request from the simulator

The issue seems to be in the firewall. When I allow an iOS app it permits the app to access the network, but the iOS simulator does not seem to have permissions. The firewall gets confused - the simulator doesn't have permissions so the network request is blocked pending approval from me, but the firewall doesn't 'see' the simulator, instead it sees the iOS app and gives that permission.

The problems comes from Xcode, it should set the firewall permissions when you install it but sometimes it fails. There is an easy fix - I've got a script that opens up the firewall to the simulator. It turns the firewall off (so make sure you are disconnected from the internet or not anywhere dodgy), enables Xcode and the iOS simulator as a firewall exception, then turns it back on.

#temporarily shut firewall off:
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate off

#put Xcode as an exception:
/usr/libexec/ApplicationFirewall/socketfilterfw --add /Applications/Xcode.app/Contents/MacOS/Xcode

#put iOS Simulator as an exception:
/usr/libexec/ApplicationFirewall/socketfilterfw --add /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator

#re-enable firewall:
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate on  

Run this, give it your password as it needs sudo access and bingo, problem goes away. You may need to run this every time Xcode is updated though...