This commonly occurs when there is an issue with your dock connector. It is likely dirty, obstructed in some way, or possibly even broken with a bent pin or something. Very often this is not apparent, because with 30 pins to play with, chances are most of the time you only need the ones for charging and USB data transfer, leaving the rest unused such that you will not notice if they start working sub optimally.
There are 3 ways I would try to fix this, in order of most likely to fix:
Clear it out
Your first step is to check for any obvious blockage. If you have a can of compressed air, you can try to blow any debris out. If you don't, then using a fine non metallic scraper (a plastic toothpick is ideal, a wooden one may leave small fibers behind) carefully clean out what you can - even if it looks clean you will be surprised how much crap and fluff you can scrape out. Take care to blow any debris out of the phone, and not into it - i.e. hold it upright and get at it from underneath, don't sit it upside down and work from the top
Clean it up
If there is no obvious obstruction then the problem may be more subtle, a coating on one or more of the pins that is preventing a neat conductive contact, or is grounding a pin against another one for example - perhaps there has been some contact with a liquid in the past etc. You need to clean the pins to get rid of this. You will need a couple of things things - 1) some cleaning agent, 2) a lint free cloth/piece of sponge, or an old toothbrush.
For a cleaning agent, 99% isopropyl is perfect, but if you don't have that kicking around you could try a very small quantity of the neatest and purest alcoholic drink you have in the house - I've used Vodka which is by and large 50/50 alcohol and water. Don't use anything flavoured or anything that it likely to have anything other than alcohol and water in it! Especially sugars or salt!.
Using a very small amount of your cleaning agent, and keeping the phone upright so any drips fall out, and not into the phone, lightly brush or wipe the dock connector, taking care not to be rough enough to disturb the pins out of alignment. I've used a small piece of synthetic sponge and prodded it about with the same toothpick I used earlier.
If this doesn't work, then the issue could still be a physical obstruction, although it may be beyond the dock connector and more internal. Short of taking the phone to bits, there is not a lot you can do, and whilst you cannot clean the inside, you can try to dislodge anything that's stuck by using a combination of lightly tapping the phone on all 4 sides whilst playing about with the vibrate functions for alarms etc.
Using the first 2 methods above I solved the "Accessory not supported problem", but still had the intermittent docking issue.
Assuming I could not fix that one, I went to turn on Vibrate alerts (which I had previously turned off) as a workaround, only to find that after playing with all the vibrate "tones" etc it magically fixed itself!
- Note 1 It's possible that the issue is not with the connector on your phone, but on your device/cable - you can try all the above on the cable end too if doing it on your phone does not yield results.
- Note 2 If your device is failing to charge, or will only charge from a certain cable or dock, then the same fix potentially applies.