Push notification xamarin.ios在应用程序处于后台时接收通知

Push notification xamarin.ios在应用程序处于后台时接收通知,push-notification,xamarin.ios,Push Notification,Xamarin.ios,如果我的应用程序处于后台和incative状态,我如何处理通知? 现在,当我点击我的应用程序时,我会收到一个警报,它会打开我的应用程序。 但是当收到通知时,我想处理ApplicationBadgeNumber 当我的应用程序处于后台时,哪种方法侦听通知 这是我的AppDelegate.cs: public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)

如果我的应用程序处于后台和incative状态,我如何处理通知? 现在,当我点击我的应用程序时,我会收到一个警报,它会打开我的应用程序。 但是当收到通知时,我想处理ApplicationBadgeNumber

当我的应用程序处于后台时,哪种方法侦听通知

这是我的AppDelegate.cs:

public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            PushNotificationManager.DidRegisterRemoteNotifications(deviceToken);
        }

        public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
        {
            PushNotificationManager.RemoteNotificationRegistrationFailed(error);
        }

public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
        {
            PushNotificationManager.DidReceiveMessage(userInfo);
}
public override void registeredForremotentifications(UIApplication应用程序,NSData deviceToken)
{
PushNotificationManager.DidRegisterRemomentNotifications(设备停止);
}
远程通知的公共覆盖无效注册失败(UIApplication应用程序,N错误)
{
PushNotificationManager.RemoteNotificationRegistration失败(错误);
}
public override void DidReceiveEmotentification(UIApplication应用程序、NSDictionary userInfo、Action completionHandler)
{
PushNotificationManager.DidReceiveMessage(用户信息);
}

事实上,苹果推送通知是由iOS而不是你的应用程序处理的。我们无法在收到推送通知时更改徽章。只有当用户点击通知时,才会触发DidReceiveEmotentification。所以用这种方法更新徽章号码是不明智的

当我们处于后台状态时,我们可以通过在推送通知包中发送“badge”参数来更改徽章编号

样本有效载荷:

{
    "aps" : {
        "alert" : "message",
        "badge" : 2
    }
}
你的应用程序图标将显示2。这里的要点是,徽章计数的计算应该在服务器端完成


请注意,有效负载中的badge参数必须是整数

你的意思是你想在后台处理applicationBadgeNumber而不点击通知吗?是的,没错。当我在debug Modus中收到消息和即时消息时,我的应用程序处于后台,徽章号会增加。如果我没有处于调试模式,并且收到通知,则徽章号不会增加,因为我的应用程序未激活。解决方案是什么?不,不可能。
didReceiveMemotentification
只有在我们点击通知后才会触发。但是什么样的应用程序处理这个问题呢?如果我关闭whats应用程序并收到一条消息,IconBadgeNumber将增加