How does Facebook Messenger clear push notifications from the lock screen if you’ve read them on desktop?

See the Multitasking Enhancements and the silent push notifications in particular. Using the silent push you can notify your app that new content is available and also download that content and/or set the badge number for example without displaying the notification in the "Notification Center". You'll have to set the UIBackgroundModes with the remote-notification value in order to make this work.

You can send silent push if the user has seen the content on another platform and clear the badge number on your iOS app.


One simple way to achieve this effect is to send a normal push notification to your device with a payload that only contains a badge count of 0.

In Facebook's example, they clearly have enough server power to simply detect when you've read the message on your desktop and send a push to your devices to makes sure that notification is no longer there.

I'm not saying this is how FB does it but it's a simpler path that may or may not fit your needs. Keep in mind that background tasking consumes your user's battery significantly and should be avoided when possible.


This is a new feature on iOS 7 called Silent Push Notification, its a multitasking feature.

What you will need:

1 - Register for Remote Notifications in didFinishLaunchingWithOptions:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
     (UIRemoteNotificationTypeNewsstandContentAvailability|
      UIRemoteNotificationTypeBadge |
      UIRemoteNotificationTypeSound |
      UIRemoteNotificationTypeAlert)];

}

2 - Implement following method in ApplicationDelegate:

   - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
      handler(UIBackgroundFetchResultNewData);


    // Possibl Results:
//    typedef enum {
//        UIBackgroundFetchResultNewData, //Download success with new data
//        UIBackgroundFetchResultNoData,  //No data to download
//        UIBackgroundFetchResultFailed   //Downlod Failed
//    } UIBackgroundFetchResult;
}

3 - Set UIBackgroundModes inside Application info.plist:

> <key>UIBackgroundModes</key> <array>
>     <string>remote-notification</string> </array>