Does an iOS app receive messages while the mobile device is locked, in sleep mode, or the app is in the background?

No, PubNub realtime messages are only received by an iOS app when the app is in the foreground (active). To wake up an app that is in the background (or not running at all), use Mobile Push Notifications (based on APNS).

Messages published while the app was in background (or the device was locked or asleep) can be retrieved via the History API (with enabled Storage/Replay add-on feature).