Push notification ReceivedRemoteNotification与DidReceiveDemotonification之间的关系
你相信吗,当我搜索这个的时候,没有一个结果。developer.Xamarin上的Xamarin API也没有提到两者之间的任何关系 让事情更复杂的是,developer.apple说,Push notification ReceivedRemoteNotification与DidReceiveDemotonification之间的关系,push-notification,xamarin.ios,remote-notifications,Push Notification,Xamarin.ios,Remote Notifications,你相信吗,当我搜索这个的时候,没有一个结果。developer.Xamarin上的Xamarin API也没有提到两者之间的任何关系 让事情更复杂的是,developer.apple说,DidReceiveRemoteNotification不受欢迎,但没有提到developer.xamarin的这种不受欢迎。此外,它还指导您如何使用它 因此,现在混合中还有WillPresentNotification 有人能解释一下这些吗?具体来说,它们是如何关联的,以及何时使用哪一种。我建议大家阅读一下苹果
DidReceiveRemoteNotification
不受欢迎,但没有提到developer.xamarin的这种不受欢迎。此外,它还指导您如何使用它
因此,现在混合中还有WillPresentNotification
有人能解释一下这些吗?具体来说,它们是如何关联的,以及何时使用哪一种。我建议大家阅读一下苹果发布iOS 10+后的新设计模式 过去的远程通知总是由
uiapplicationelegate
协议/接口来处理,由于您的AppDelegate
类默认实现该协议,因此通常的做法是从那里处理传入的远程通知,而现在没有这么多使用
应用程序:didReceiveMemotentification:fetchCompletionHandler:
在iOS 10+中,苹果将通知抽象到UNUserNotificationCenter
框架中
为了分配委托,您必须将unuservificationcenter.Current.delegate
分配给从usernotificationcenteredelegate
进行子casses的自定义类,或者像我一样,让您的AppDelegate
实现接口并在那里处理事情
下面是我如何在Xamarin.iOS
中实现的:
using Foundation
using UIKit;
using UserNotifications;
public class AppDelegate : UIApplicationDelegate, IUNUserNotificationCenterDelegate
{
public override UIWindow Window { get; set; }
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
UNUserNotificationCenter.Current.Delegate = this;
return true;
}
[Export("userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:")]
public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, System.Action completionHandler)
{
//Handle Notification if user interacts with notification in Notification Center of iOS.
}
[Export("userNotificationCenter:willPresentNotification:withCompletionHandler:")]
public void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, System.Action<UNNotificationPresentationOptions> completionHandler)
{
//Handle Notification if app is in the foreground when recieved.
}
}
<代码>使用基础
使用UIKit;
使用用户通知;
公共类AppDelegate:UIApplicationDelegate、IUNUserNotificationCenterDelegate
{
公共覆盖UIWindow窗口{get;set;}
公共覆盖bool FinishedLaunching(UIApplication应用程序、NSDictionary启动选项)
{
UNUserNotificationCenter.Current.Delegate=此;
返回true;
}
[导出(“userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:”)]
public void direceiveNotificationResponse(UnuseNotificationCenter、UNNotificationResponse、System.Action completionHandler)
{
//如果用户与iOS通知中心中的通知交互,则处理通知。
}
[导出(“userNotificationCenter:willPresentNotification:withCompletionHandler:”)]
public void WillPresentNotification(未使用通知中心、未通知通知通知、系统操作完成处理程序)
{
//如果收到应用程序时应用程序位于前台,则处理通知。
}
}
当然,如果您不熟悉这些类,您会想看看框架,看看如何实现类,例如
未通知
和未通知
响应。我建议您阅读苹果发布iOS 10+后的新设计模式
过去的远程通知总是由uiapplicationelegate
协议/接口来处理,由于您的AppDelegate
类默认实现该协议,因此通常的做法是从那里处理传入的远程通知,而现在没有这么多使用
应用程序:didReceiveMemotentification:fetchCompletionHandler:
在iOS 10+中,苹果将通知抽象到UNUserNotificationCenter
框架中
为了分配委托,您必须将unuservificationcenter.Current.delegate
分配给从usernotificationcenteredelegate
进行子casses的自定义类,或者像我一样,让您的AppDelegate
实现接口并在那里处理事情
下面是我如何在Xamarin.iOS
中实现的:
using Foundation
using UIKit;
using UserNotifications;
public class AppDelegate : UIApplicationDelegate, IUNUserNotificationCenterDelegate
{
public override UIWindow Window { get; set; }
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
UNUserNotificationCenter.Current.Delegate = this;
return true;
}
[Export("userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:")]
public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, System.Action completionHandler)
{
//Handle Notification if user interacts with notification in Notification Center of iOS.
}
[Export("userNotificationCenter:willPresentNotification:withCompletionHandler:")]
public void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, System.Action<UNNotificationPresentationOptions> completionHandler)
{
//Handle Notification if app is in the foreground when recieved.
}
}
<代码>使用基础
使用UIKit;
使用用户通知;
公共类AppDelegate:UIApplicationDelegate、IUNUserNotificationCenterDelegate
{
公共覆盖UIWindow窗口{get;set;}
公共覆盖bool FinishedLaunching(UIApplication应用程序、NSDictionary启动选项)
{
UNUserNotificationCenter.Current.Delegate=此;
返回true;
}
[导出(“userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:”)]
public void direceiveNotificationResponse(UnuseNotificationCenter、UNNotificationResponse、System.Action completionHandler)
{
//如果用户与iOS通知中心中的通知交互,则处理通知。
}
[导出(“userNotificationCenter:willPresentNotification:withCompletionHandler:”)]
public void WillPresentNotification(未使用通知中心、未通知通知通知、系统操作完成处理程序)
{
//如果收到应用程序时应用程序位于前台,则处理通知。
}
}
当然,如果您不熟悉这些类,您需要查看框架以了解如何实现类,例如
UNNotification
和UNNotification
response。应用程序:didReceiveMemotentification:fetchCompletionHandler:
未被弃用。它仍然需要处理后台通知(那些唤醒你的应用程序在后台做事情的通知)
UNUserNotificationCenter主要处理与UI相关的通知或操作,但仍然无法处理后台通知。
应用程序:DidReceiveMemoteNotification:fetchCompletionHandler:
未被弃用。它仍然需要处理后台通知(那些唤醒你的应用程序在后台做事情的通知)
UNUserNotificationCenter主要处理与UI相关的通知或操作,但仍然无法处理后台通知