I found the solution. In my project info under Build > Code Signing Identity I had it set to automatic, and it was selecting an AdHoc distribution profile which did not have push notifications enabled. (It was the wrong one.) I have selected the correct profile and the error is gone.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…