Hi
Apple accessories are covered by Apple's Limited Warranty against defects in materials and workmanship, but not against accidental damage or misuse.
Follow the instructions here:
If your headphones don't work with your iPhone, iPad, or iPod touch - Apple Support
If the issue persists, contact Apple Support, make a Genius Bar reservation or visit an Apple Authorised Service Provider with a view to having your headphones checked and, if eligible, replaced under warranty: