Updating from Capacitor 3 to Capacitor 4
Compared to previous upgrades, the breaking changes between Capacitor 3 and 4 are fairly minimal. In this guide, you'll find steps to update your project to the current Capacitor 4 version as well as a list of breaking changes for our official plugins.
Using the CLI to Migrate
Install the latest version of the Capacitor CLI to your project using npm i -D @capacitor/cli@latest-4. Once installed, simply run npx cap migrate to have the CLI handle the migration for you. If any of the steps for the migration are not able to be completed, additional information will be made available in the output in the terminal. The steps for doing the migration manually are listed out below.
iOS
The following guide describes how to upgrade your Capacitor 3 iOS project to Capacitor 4.
Raise iOS Deployment Target
Do the following for your Xcode project: select the Project within the project editor and open the Build Settings tab. Under the Deployment section, change iOS Deployment Target to iOS 13.0. Repeat the same steps for any app Targets.
Then, open ios/App/Podfile and follow these steps:
- Add this on the first line:
require_relative '../../node_modules/@capacitor/ios/scripts/pods_helpers'
- Update the iOS version to 13.0:
platform :ios, '13.0'
- Add this block on the last line:
post_install do |installer|
assertDeploymentTarget(installer)
end
Remove Unnecessary Code
Remove unused touchesBegan method from AppDelegate.swift
-override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
- super.touchesBegan(touches, with: event)
-
- let statusBarRect = UIApplication.shared.statusBarFrame
- guard let touchPoint = event?.allTouches?.first?.location(in: self.window) else { return }
-
- if statusBarRect.contains(touchPoint) {
- NotificationCenter.default.post(name: .capacitorStatusBarTapped, object: nil)
- }
-}
Optional: Remove NSAppTransportSecurity entry from Info.plist
NSAppTransportSecurity is only used for live reload, if you are not using live reload or you are using Ionic CLI for live reload you no longer need this entry.
-<key>NSAppTransportSecurity</key>
-<dict>
- <key>NSAllowsArbitraryLoads</key>
- <true/>
-</dict>