Here’s what the theory actually says: if you know the number of iterations exactly, it’s a Nash equilibrium for both to defect on all iterations. But if you know the chance that this iteration will be the last, and this chance isn’t too high (e.g. below 1⁄3, can’t be bothered to give an exact value right now), it’s a Nash equilibrium for both to cooperate as long as the opponent has cooperated on previous iterations.
The theory says to defect in the iterated dilemma as well (under some assumptions).
Here’s what the theory actually says: if you know the number of iterations exactly, it’s a Nash equilibrium for both to defect on all iterations. But if you know the chance that this iteration will be the last, and this chance isn’t too high (e.g. below 1⁄3, can’t be bothered to give an exact value right now), it’s a Nash equilibrium for both to cooperate as long as the opponent has cooperated on previous iterations.