How do I load an HTTP URL with App Transport Security enabled in iOS 9?

Matheus Mello
Matheus Mello
September 2, 2023
Cover Image for How do I load an HTTP URL with App Transport Security enabled in iOS 9?

How to Load an HTTP URL with App Transport Security Enabled in iOS 9 📲💻

So, you're a developer working on an iOS app and you want to load an HTTP URL with App Transport Security (ATS) enabled in iOS 9. By default, ATS enforces secure connections using HTTPS, which is great for user privacy and security. However, there may be situations where you need to load HTTP URLs, either for local development or for connection to a web service on your local machine. This blog post will guide you through the process and provide easy solutions to this common problem. Let's dive in! 🚀

Understanding App Transport Security (ATS) 🕵️‍♂️🔒

First, let's clarify what App Transport Security (ATS) is. ATS is a feature introduced in iOS 9 that enforces secure network connections. It ensures that your app uses secure communication protocols, such as HTTPS, by default. ATS improves the privacy and security of user data and prevents certain security vulnerabilities. However, it can cause issues when trying to load HTTP URLs.

The Challenge: Loading HTTP URLs with ATS Enabled 😓🔐

In your specific case, you mentioned that you have a local development environment where you need to connect to a web service running on your laptop. This web service is using HTTP instead of HTTPS. When you try to load the HTTP URL in your iOS app, ATS automatically replaces it with an HTTPS URL, which is not what you want.

The Solution: Disabling ATS for Specific URLs 🤔💡

To load HTTP URLs with ATS enabled in iOS 9 or later, you can make use of the NSAppTransportSecurity key in your app's Info.plist file. Here's how you can do it:

  1. Open your Xcode project and locate the Info.plist file.

  2. Add a new entry by clicking on the "+" button. Name it NSAppTransportSecurity and make it a dictionary type.

  3. Inside NSAppTransportSecurity, add a sub-entry named NSAllowsArbitraryLoads and set its value to YES.

Here's what your Info.plist file should look like:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

By setting NSAllowsArbitraryLoads to YES, you are instructing iOS that it is allowed to load both HTTP and HTTPS URLs. This will disable ATS for all URLs in your app, not just the specific ones you want to load via HTTP.

✔️ Note: Disabling ATS should only be done for local development or debugging purposes. It is important to ensure that your app uses secure connections (HTTPS) in a production environment to protect user data.

Secure Alternative: Using HTTPS for Local Development 🌐🔐

While disabling ATS might be necessary for local development, it's essential to use secure connections whenever possible. Consider setting up HTTPS in your local development environment to align with best practices and improve the overall security of your app.

You can generate a self-signed SSL certificate and configure your web service to use HTTPS. By doing this, you'll be able to access your web service using a secure connection in your app.

Engage and Share! 📢📲✅

We hope this guide helps you load HTTP URLs with App Transport Security enabled in iOS 9. Remember to disable ATS only for local development and use secure connections (HTTPS) for your production environment.

If you found this blog post helpful, please share it with your fellow iOS developers! And don't forget to let us know in the comments if you have any questions or other topics you'd like us to cover in future blog posts. Happy coding! 💻🙌


References:

Take Your Tech Career to the Next Level

Our application tracking tool helps you manage your job search effectively. Stay organized, track your progress, and land your dream tech job faster.

Your Product
Product promotion

Share this article

More Articles You Might Like

Latest Articles

Cover Image for How can I echo a newline in a batch file?
batch-filenewlinewindows

How can I echo a newline in a batch file?

Published on March 20, 2060

🔥 💻 🆒 Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Cover Image for How do I run Redis on Windows?
rediswindows

How do I run Redis on Windows?

Published on March 19, 2060

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! 🚀 Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Cover Image for Best way to strip punctuation from a string
punctuationpythonstring

Best way to strip punctuation from a string

Published on November 1, 2057

# The Art of Stripping Punctuation: Simplifying Your Strings 💥✂️ Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Cover Image for Purge or recreate a Ruby on Rails database
rakeruby-on-railsruby-on-rails-3

Purge or recreate a Ruby on Rails database

Published on November 27, 2032

# Purge or Recreate a Ruby on Rails Database: A Simple Guide 🚀 So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? 🤔 Well, my