After the App Store automatically updated Xcode to version 7 (without me actually wanting this for now, but hey …) running
ionic emulate ios -c -l would not do much anymore:
- The app would launch but get stuck at the loading screen
console.log()calls would be logged
Fixing it manually
To fix this, update the
platforms/ios/projectname/projectname-Info.plist file with the following settings:
<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict>
Add the snippet above at the end of the file, right before the closing
Do note that you’ll have to (re)do this every time you run
ionic platform add ios (which can happen when working in a team with multiple people)
Fixing it automatically
Alternatively you can use a
before_emulate hook to have this change applied automatically before starting the iPhone Simulator.
- Put the contents below in
- Make the script executable (
chmod 755 ./hooks/before_emulate/010_ios_allowarbitraryloads.sh)
Every time you (or one of your teammates) runs
ionic emulate ios it will check if the change in
platforms/ios/projectname/projectname-Info.plist has already been made or not. If not, the settings are added.
#!/bin/bash # Allow iPhone Simulator to make Arbitrary Loads # @ref https://www.bram.us/2015/09/29/ionic-emulate-vs-xcode-7/ XCODEVERSION=`xcodebuild -version | grep Xcode | sed 's/Xcode //g'` XCODEMAINVERSION=`echo $XCODEVERSION | cut -d "." -f 1` PROJECTNAME=`xmllint --format --xpath "//*[local-name()='widget']/*[local-name()='name']/text()" config.xml` if [[ "$CORDOVA_PLATFORMS" == "ios" ]] then if [[ "$XCODEMAINVERSION" > 6 ]] then echo "iPhone Simulator (XCode $XCODEVERSION) is being used. We might need to adjust $PROJECTNAME-Info.plist to allow Arbitrary Loads!" PLISTBUDDY="/usr/libexec/PlistBuddy" TARGET="platforms/ios/$PROJECTNAME/$PROJECTNAME-Info.plist" HASSETTING=`$PLISTBUDDY -c "print :NSAppTransportSecurity:NSAllowsArbitraryLoads" "$TARGET" 2>&1` if [[ "$HASSETTING" == "true" ]] then echo " - NSAllowsArbitraryLoads already enabled. Not adjusting $PROJECTNAME-Info.plist" else echo " - NSAllowsArbitraryLoads not enabled. Adjusting $PROJECTNAME-Info.plist" $PLISTBUDDY -c "Add :NSAppTransportSecurity dict" "$TARGET" $PLISTBUDDY -c "Add :NSAppTransportSecurity:NSAllowsArbitraryLoads bool YES" "$TARGET" fi fi fi
I don’t run ads on my blog nor do I do this for profit. A donation however would always put a smile on my face though. Thanks!