An old problem that we still see from time to time is an Apple Lightning cable that will only work when it is plugged into the device a certain way. Most usually this problem affects charging, but it can affect data transfer as well.
There are a couple of ways to solve this problem: both involve simply cleaning the dirty contacts.
The “low tech” way is to use a pencil eraser. It takes a bit of patience and some hard work but usually after a few minutes of scrubbing, the dirt will come off and the cable will be as good as new.
If that doesn’t work (or if you don’t like the idea of scrubbing away with an eraser) you’ll need to switch up a gear. This requires some slightly more specialised equipment though- some contact cleaner and a fibre glass brush will do the trick in a few seconds.