Except that the apps help sell the phone. Just look at Apple's marketing since the App Store came out. Having an ecosystem of easily accessible free and paid apps is a huge driver in terms of the iPhone's popularity.
Your Walmart analogy would make more sense if Walmart sold tickets for admission. For example, Costco, a store that does in fact sell memberships, does buy and resell some products for no margin or even at a loss in order to cultivate a variety of goods to incentivize people to maintain a membership.