Google was getting their butt kicked by Chinese competitors, namely Baidu. They weren't exactly making tons of money anyway. So they gracefully did a PR move and pulled out of China.
Apple makes a lot of money in china. Much much more than local Chinese mobile phone producers. Huawei might sell more phones than Apple, but their margins are slim to negative.