so, I was working on my father's iphone 8 a few days ago, and connected it via usb cable to my 15" macbook pro (2015)
It kept mounting and dismounting, and charging seemed to be cycling, lasting only a second or two before cycling again.
I thought it was perhaps a dodgy cable, so of course tried another. Same same.
Thought then it must be the phone (bought s/hand) so tried my phone (8+), same same (I usually charge my phone via wireless charger, so hadn't noticed this issue before).
Then tried father's phone with first cable in my 2012 17" macbook pro, all hunky-dory and fine. My phone, hunky dory
After doing some googling, I found someone who recommended this command line prompt to try to resolve the issue, and it worked - it would then charge and remain mounted on the 15" 'book
sudo killall -STOP -c usbd
I wondered if this daemon might also be affecting the sd card slot reader, since it is also usb (internal), so I mounted the sd card on the 15".
That was 3 days ago, and it hasn't unmounted since. Could be unrelated and merely coincidental, serendipitous good fortune, but might be worth a try.
As usual, I recommend not trying with anything that has data that cannot be replaced.
Cheers!