Fix iOS stuck in infinite loop bug