Apple Inc. snapped out of three straight quarters of falling revenue as strong demand for the iPhone 7 raised investors’ hopes that the technology giant is emerging from its roughest period since it reinvented the market for mobile devices.