I want to show an alert view when my iOS app is in the background (and it's using location).
For example, the Uber Partner (Driver) app shows an alert and plays a sound even when:
I am aware of the local notifications approach and it doesn't work if the user turns off/ changes the Notifications in Settings. I am looking for something different.
Actions performed to reach the above state:
Of course, silent remote notifications can be tapped in by the app using the didReceiveRemoteNotification: fetchCompletionHandler:
API even if the user disables Notifications in Settings. But, how the alert is popped up, that's what I am trying to find out.
Go to Settings>General>Background App Refresh and you can see what other apps are allowed to update data in the background. iOS dynamically manages memory without any user intervention. The only apps that are really running in the background are music or navigation apps.
Apple does not offer a way to handle a notification that arrives when your app is closed (i.e. when the user has fully quit the application or the OS had decided to kill it while it is in the background). If this happens, the only way to handle the notification is to wait until it is opened by the user.
Banner notifications on your iPhone are alerts that drop down from the top of your screen whenever you receive a notification from an app. You can enable or disable Banner notifications on an app-by-app basis through your iPhone's Settings app.
Go to Settings and tap Notifications. Select an app under Notification Style. Under Alerts, choose the alert style that you want. If you turn on Allow Notifications, choose when you want the notifications delivered — immediately or in the scheduled notification summary.
I would imagine that Uber has some special permissions or uses some private API that allow them to achieve this behavior without using local notifications. While I don't know how Uber implemented this in their partner app, I can talk a little bit about how alerts work on the home screen.
SpringBoard is the singleton class that manages the SpringBoard application (SpringBoard.app), the application launcher for the iPhone. SpringBoard doesn't use the standard UIAlertView
/UIAlertController
classes, since they don't participate in the SpringBoard-wide alert system. iOS 5 introduced SBAlertItem
the which is used to display UIAlertViews on SpringBoard (Battery Notification Alerts, Sim Unlock Alert, etc.). Apple uses SBAlertItem
for their lock and home screen alerts, I'll be working on the assumption that Uber is using an SBAlertItem
for this answer.
SBAlertItem
has a protected ivar UIAlertView *_alertSheet
. Assuming this acts as a normal UIAlertView
, you should be able to change the properties on this alert to fit your needs. I would also read through saurik's Cydia Substrate project, specifically MobileSafety.mm to see some use cases. I've also found noweibogoodsleep which provides an example of using SBAlertItem
on the SpringBoard.
I've also found SBUserNotificationAlert
, a subclass of SBAlertItem
. This appears to have more methods to facilitate alert customization that may fit your needs better than the standard SBAlertItem
.
I realize hooking into private APIs is probably not what you were expecting when asking this question. Since I don't know how Uber works, I can only provide an answer from my personal experience working with the runtime and jailbroken devices.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With