简体   繁体   English

如果您在桌面上阅读过 Facebook Messenger,它如何清除锁定屏幕上的推送通知?

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

When I receive a message on Facebook I get a push notification on a lock screen (iOS).当我在 Facebook 上收到消息时,我会在锁定屏幕 (iOS) 上收到推送通知。 Then I read this message on desktop.然后我在桌面上阅读了这条消息。 Right after that this push notification disappear without any interactions with the phone.紧接着这个推送通知消失了,与手机没有任何交互。 How can I implement the same thing myself for removing outdated notifications?我怎样才能自己实现同样的事情来删除过时的通知?

The second usage could be stitching notifications together.第二种用法可能是将通知拼接在一起。 For instance Instagram sends you a push when someone liked your photo.例如,当有人喜欢您的照片时,Instagram 会向您发送推送。 After 20 likes your notifications screen is ruined and unreadable. 20 个赞后,您的通知屏幕已损坏且无法阅读。 But using the same principal as Facebook does it seem to be possible remove previous notification of the same sort and create new with the increased counter.但是使用与 Facebook 相同的主体似乎可以删除相同类型的先前通知并使用增加的计数器创建新通知。 No "User A liked photo X, User B liked photo Y etc", but "20 users liked photo Z" instead.没有“用户 A 喜欢照片 X,用户 B 喜欢照片 Y 等”,而是“20 个用户喜欢照片 Z”。

I've seen couple of treads on similar topics here, but still no answer so far.我在这里看到了类似主题的几个步骤,但到目前为止仍然没有答案。 Thanks!谢谢!

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.您必须使用 remote-notification 值设置 UIBackgroundModes 才能使其工作。

You can send silent push if the user has seen the content on another platform and clear the badge number on your iOS app.如果用户在其他平台上看到了内容并清除了您的 iOS 应用程序上的徽章编号,您可以发送静默推送。

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.实现此效果的一种简单方法是向您的设备发送普通推送通知,其有效负载仅包含徽章计数为 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.在 Facebook 的例子中,他们显然有足够的服务器能力来简单地检测你何时阅读了桌面上的消息并向你的设备发送推送以确保通知不再存在。

I'm not saying this is how FB does it but it's a simpler path that may or may not fit your needs.我并不是说这就是 FB 的做法,但它是一条更简单的路径,可能适合也可能不适合您的需求。 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.这是 iOS 7 上的一项新功能,称为 Silent Push Notification,它是一项多任务处理功能。

What you will need:你需要什么:

1 - Register for Remote Notifications in didFinishLaunchingWithOptions: 1 - 在 didFinishLaunchingWithOptions 中注册远程通知:

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

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

}

2 - Implement following method in ApplicationDelegate: 2 - 在 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: 3 - 在 Application info.plist 中设置 UIBackgroundModes:

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

Warning: I have not tried this, it's just an idea!警告:我还没有尝试过,这只是一个想法!

In iOS 7 you could try sending a silent 'content-available' notification to the user.在 iOS 7 中,您可以尝试向用户发送无声的“内容可用”通知。 This would wake the app up in the background and allow you to run some code.这将在后台唤醒应用程序并允许您运行一些代码。 In the background you could then do在后台你可以做

[[UIApplication sharedApplication] setApplicationBadgeNumber:0];
[[UIApplication sharedApplication] setApplicationBadgeNumber:newBadgeNumber];

this should clear any notifications that are in the notification centre.这应该清除通知中心中的任何通知。 You could then post a local notification with the data that came through in your userInfo dictionary, and it would appear as if the old ones were replaced by the new one!然后,您可以使用 userInfo 字典中通过的数据发布本地通知,并且看起来好像旧的被新的替换了!

Again, just an idea...再次,只是一个想法......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .cancelAllLocalNotifications是否清除推送通知? - Does .cancelAllLocalNotifications clear push notifications? 如果您在事先同意后禁用通知,Apple如何处理推送令牌? - How does Apple handle push tokens if you disable notifications after agreeing to them prior? 有没有一种方法可以仅将推送通知发送到锁定屏幕? - Is there a way to send push notifications only to the lock screen? 您可以通过代码或推送通知激活 iPhone 锁屏吗? - Can you activate the iPhone lock screen from code or push notification? 如何从服务器端清除设备上未读的推送通知? - How to clear unread push notifications on the device from serverside? 在AppDelegate中清除NSMutableDictionary中的几个推送通知 - Clear several Push Notifications from NSMutableDictionary in AppDelegate 如何在请求视频和音频呼叫时接收全屏通知,例如 flutter 中的 Facebook 信使 - How can I receive full-screen notifications when video and audio calls are requested like a Facebook messenger in flutter 在锁定屏幕iOS上显示交互式本地推送通知 - Display interactive local push notifications on lock screen iOS 如何在Messenger中设置远程推送通知的应用程序 - How to setup application for Remote Push Notifications like in Messenger 如何以编程方式清除推送通知-iOS - How to clear push notifications programmatically-iOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM