Dealing with App Transport Security in Xcode

Xcode iOS Networking

Posted on 12 Apr 2023 . 2 min read


What is App transport security(ATS)?


App transport security improves user security and privacy by making secure connections to network.


When we try to make network requests, a console error has been printed.


App Transport Security has blocked a cleartext HTTP connection since 
it is insecure. Use HTTPS instead or add Exception Domains to your 
app's Info.plist.


It indicates that ATS is blocking insecure connections. You must use HTTPS in the URL to make secure connections or update the Info.plist file with a key that grants a temporary exemption.


The info.plist file is a dictionary of information about an app used while deploying it to the App Store. Adding the ATS exemption key in the info.plist file means we are saying that app might make insecure connections.


Open the info.plist file from the project navigator, and you will see the default set of keys for an app.


Click on "Information Property List" and plus sign (+) will appear. To add a new key to the file, click the plus sign (+). To allow HTTP requests, you have to add the key "App Transport Security Settings".


Image App Transport Security Settings


App Transport Security Security Settings has a dictionary value. Click on the key name, then click on the plus sign (+), and add the key "Allow Arbitrary Loads". The value of this key is a boolean that should be set to "Yes".



Image Allow Arbitrary Loads

The bottom line


While working with network requests, always try to work with a secure HTTPS network. It helps the app perform secure network requests. If your API does not provide a secure connection, then use an exemption key to perform network requests.


Don’t hesitate to contact me if you have any questions or queries. Follow me on twitter @gurjitpt for any updates.

Thanks!


More articles:


Share this article



Written By

Generic placeholder image

Gurjit Singh

I’m Computer Science graduate and an iOS Engineer who writes about Swift and iOS development. Follow me for more updates:


Discover articles by topics

SwiftUI Class Struct Networking XCode NSCache Enum Optionals Property Observers Closures Guard Reviews StoreKit App Store Algorithms Testing Operators Protocol Extensions Weak Unowned SwiftData WWDC23 GCD API Admob SwiftLint Lottie Foreach Objective-C UIKit NavigationSplitView

Related Articles


String Concatenation in Swift: A Comprehensive Guide

In any programming language, working with strings is essential, and Swift is no different.Whether you are building iOS apps......

2024-10-17 . 3 min read     String Concatenation

Read More »

Integrating SwiftUI with UIKit Using UIHostingController

With the introduction of SwiftUI, Apple has provided developers with a modern way to build user interfaces across all Apple platforms....

2024-07-09 . 3 min read     UIHostingController

Read More »

Deep Dive into Autorelease Pools in Swift

In the realm of software development, memory management plays a crucial role in ensuring the efficient allocation and deallocation of memory...

2024-01-28 . 4 min read     Swift Autorelease

Read More »

Swift enum equatable: with or without associated values

Swift enums provide a powerful way to model a set of related values. Enums can be equipped with associated values, allowing them to represen...

2024-01-24 . 3 min read     Swift Enums

Read More »

How to create Date Picker in SwiftUI

Use a DatePicker when creating a view that enables users to choose both a calendar date and, if needed, a specific time.In SwiftUI, you can ...

2024-01-16 . 2 min read     SwiftUI DatePicker

Read More »

Getting started with Swiftlint to enforce Swift style

SwiftLint is a tool that ensures Swift code adheres to defined style guidelines. It automates code review by identifying and suggesting impr...

2023-12-29 . 4 min read     Swift SwiftLint

Read More »