因此,我已根据此处提到的指南以Xamarin形式创建了iOS通知服务扩展 [https://docs.microsoft.com/en-us/xamarin/ios/platform/user-notifications/enhanced-user-notifications?tabs=windows][1]
这是我的扩展代码,与上述示例完全相同
[Register("NotificationService")]
public class NotificationService : UNNotificationServiceExtension
{
Action<UNNotificationContent> ContentHandler { get; set; }
UNMutableNotificationContent BestAttemptContent { get; set; }
protected NotificationService(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
}
public override void DidReceiveNotificationRequest(UNNotificationRequest request, Action<UNNotificationContent> contentHandler)
{
ContentHandler = contentHandler;
BestAttemptContent = (UNMutableNotificationContent)request.Content.MutableCopy();
// Modify the notification content here...
BestAttemptContent.Title = $"{BestAttemptContent.Title}[modified]";
ContentHandler(BestAttemptContent);
}
public override void TimeWillExpire()
{
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
ContentHandler(BestAttemptContent);
}
}
但是我无法调试通知有效负载,也无法接收通知,正在注册,所以我假设我的配置正确,但是服务扩展无法运行
我是否缺少任何内容,任何输入都将有所帮助,例如,我正在为此使用Azure Notification Hub
答案 0 :(得分:1)
确保您使用精确的捆绑包配置文件而不是通配符配置文件对应用程序进行了签名,并且请记住模拟器不支持通知,所有这些都适用于“仍将进行注册”的情况。
如果有疑问,请检查您的通知是否可以在真实设备上临时发布,如果是的话,则是上述原因。