Telefonica has been grappling with intense competition in an increasingly low-cost Spanish market.