ConnectionManager如何获得在AndroidPush类中捕获的expiredRegistrationId?
我这样做是错误的吗?
有关如何改进解决方案的任何建议?
我可以遵循任何模式吗?
解决方案:经理
public class ConnectionManger
{
private readonly IPushManager pushManager = new PushManager();
public void NotifyAppUser(List<PushNotificationSubscription> regIds, Alert alert)
{
pushManager.PushNotification(regIds, alert);
var expiredRegistrationId = ??
}
}
解决方案:PushNotification
public class PushManager : IPushManager
{
public void PushNotification(List<PushNotificationSubscription> registeredPhone, Alert alert)
{
AndroidPush androidPush = new AndroidPush();
androidPush.Push(alert, registeredPhone);
}
}
public class AndroidPush : IPushNotificationStrategy
{
public void Push(Alert alert, List<string> registrationIds)
{
// Wait for GCM server
#region GCM Events
gcmBroker.OnNotificationFailed += (notification, aggregateEx) =>
{
var expiredRegistrationId = aggregateEx.OldId;
Q: How do i pass expiredRegistrationId to ConnectionManager class?
};
}
}
答案 0 :(得分:0)
You have .NET as common playground so there are several options
Assuming:
then this should work:
Change your signature in the IPushNotificationStrategy interface to
List<string> Push(Alert alert, List<string> registrationIds)
Add this event to your IPushManager interface:
event Action<List<string>> ExpiredRegs;
Implement and invoke this event from PushManager:
public event Action<List<string>> ExpiredRegs;
// call this when Push returns some expiredRegs :
void OnExpiredRegs(List<string> expiredRegs) => ExpiredRegs?.Invoke(expiredRegs);
Subscribe to the event in ConnectionManger:
pushManager.ExpiredRegs += OnExpiredRegs;
void OnExpiredRegs(List<string> expiredRegs)
{
// whatever you need to do
}