I managed to solve the problem. Finally...
I did the following steps:
connected iPhone and Macbook by cable
Turned off WiFi on the Macbook
Turned off WiFi on the iPhone
Went to XCode -> Window -> Devices and Simulators -> selected iPhone from the list -> Unpair device
After that, on the iPhone, in the alert, I clicked trust the computer
After that, in the Devices and Simulators window, the iPhone connected.