After upgrading the mac OS and XCode to 13.2.1 and iPhone to 15.1, the device stopped connecting to the mac. It kept showing the error as
Failed to prepare device for development.
This answer helped me where you: