如何从远程推送通知获取 APNS 负载?
How to Get APNS payload from a remote push notification?
我正在努力在我的 OSX 应用程序中添加远程推送通知支持。我可以通过 apns 在我的 PC 中成功接收推送通知,当我单击通知横幅时,这就是我看到的行为。
如果我的应用程序不是 运行 ,它将启动该应用程序。但从不点击 "ReceivedRemoteNotification()"。这是预期的行为吗?在这种情况下,有什么方法可以接收 apns 负载吗?
如果我的应用程序是 运行,我通过 "ReceivedRemoteNotification" 获取有效负载并且一切正常。
所以如果不是 运行,我们就无法在我们的应用程序中获取 apns 负载?
非常感谢任何帮助。
谢谢,
吉特什
想通了。有效负载可通过 DidFinishLaunching 的 "NSNotification" 参数获得。
public override void DidFinishLaunching(NSNotification notification)
{
var uInfo = notification.UserInfo;
if(uInfo["NSApplicationLaunchUserNotificationKey"] != null)
{
var payLoad = uInfo["NSApplicationLaunchUserNotificationKey"] as NSUserNotification;
if(payLoad.ActivationType == NSUserNotificationActivationType.ActionButtonClicked)
{
NSAlert alert = new NSAlert();
alert.MessageText = "Button Clicked";
alert.RunModal();
}
var userInfo = payLoad.UserInfo;
//not.ActivationType ==
if (userInfo != null && userInfo.ContainsKey(new NSString("aps")))
{
//Get the aps dictionary
NSDictionary aps = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary;
if (aps.ContainsKey(new NSString("content")))
{
var deepLink = (aps[new NSString("content")] as NSString).ToString();
NSAlert alert = new NSAlert();
alert.MessageText = deepLink;
alert.RunModal();
//DisplaySubView(deepLink);
//Console.WriteLine($"Deeplink : {deepLink}");
}
}
}
我正在努力在我的 OSX 应用程序中添加远程推送通知支持。我可以通过 apns 在我的 PC 中成功接收推送通知,当我单击通知横幅时,这就是我看到的行为。
如果我的应用程序不是 运行 ,它将启动该应用程序。但从不点击 "ReceivedRemoteNotification()"。这是预期的行为吗?在这种情况下,有什么方法可以接收 apns 负载吗?
如果我的应用程序是 运行,我通过 "ReceivedRemoteNotification" 获取有效负载并且一切正常。
所以如果不是 运行,我们就无法在我们的应用程序中获取 apns 负载?
非常感谢任何帮助。
谢谢, 吉特什
想通了。有效负载可通过 DidFinishLaunching 的 "NSNotification" 参数获得。
public override void DidFinishLaunching(NSNotification notification)
{
var uInfo = notification.UserInfo;
if(uInfo["NSApplicationLaunchUserNotificationKey"] != null)
{
var payLoad = uInfo["NSApplicationLaunchUserNotificationKey"] as NSUserNotification;
if(payLoad.ActivationType == NSUserNotificationActivationType.ActionButtonClicked)
{
NSAlert alert = new NSAlert();
alert.MessageText = "Button Clicked";
alert.RunModal();
}
var userInfo = payLoad.UserInfo;
//not.ActivationType ==
if (userInfo != null && userInfo.ContainsKey(new NSString("aps")))
{
//Get the aps dictionary
NSDictionary aps = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary;
if (aps.ContainsKey(new NSString("content")))
{
var deepLink = (aps[new NSString("content")] as NSString).ToString();
NSAlert alert = new NSAlert();
alert.MessageText = deepLink;
alert.RunModal();
//DisplaySubView(deepLink);
//Console.WriteLine($"Deeplink : {deepLink}");
}
}
}