Detect if an electromagnet it touching metal (without a switch)
Those electromagnets have both poles physically on the same side, so the magnetic circuit should see a large change in reluctance when it comes in contact with a ferromagnetic material (as opposed to the field being closed in air). You should be able to see that contact as a relatively large change in inductance.

You would need to use an AC signal of a high-enough frequency to be able to apply it alongside your DC drive, or you can modify your DC drive to apply an AC component (e.g., PWM-style pulses).

Be aware that the body of the electromagnet is conductive, which means that it will present high losses to any AC excitation.