Sunscreen blocks the absorption of UVB, which is responsible for vitamin D production. So, if you’re spending a short amount of time in the sun, avoid sunscreen. If you’re out for longer, it is sensible to get sun on unprotected skin for the first 10-15 minutes (depending on the UV index), and then apply sunscreen.