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

后端 未结 4 1096
面向向阳花
面向向阳花 2020-12-07 15:36

When I receive a message on Facebook I get a push notification on a lock screen (iOS). Then I read this message on desktop. Right after that this push notification disappear

4条回答
  •  执念已碎
    2020-12-07 16:17

    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:

    > UIBackgroundModes 
    >     remote-notification 
    

提交回复
热议问题