Lightweight constrained application protocol (CoAP) has emerged as a common communication protocol for resource-constrained equipment in distribution internet of things (IoT). CoAP introduces two modes for data transmission, i.e., non-confirmed mode for reducing transmission delay and confirmed mode for reducing packet-loss ratio, which can be dynamically selected to satisfy the service requirements. However, there are still some challenges in dynamic CoAP mode selection, including incomplete information and differentiated quality of service (QoS) requirements of distributed IoT services. In this paper, we propose a upper confidence bound (UCB)-based dynamic CoAP mode selection algorithm for data transmission to address these challenges. The simulation results validate that, compared with the fixed mode selection algorithm, the proposed algorithm can flexibly balance the tradeoff between packet-loss ratio and transmission delay as well as satisfy the differentiated QoS in distribution IoT.