0

因此,我根据此处提到的指南在 Xamarin 表单中创建了一个 iOS 通知服务扩展 [ https://docs.microsoft.com/en-us/xamarin/ios/platform/user-notifications/enhanced-user-notifications?tabs =窗口][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 通知中心

4

1 回答 1

1

确保您使用精确的捆绑配置文件而不是通配符配置文件签署了应用程序,并记住模拟器不支持通知,所有这些都适用于“注册仍将进行”。

如果有疑问,请检查您的通知是否在真实设备上以临时版本的形式工作,如果是,那么上述原因就是原因。

于 2020-01-13T15:25:10.570 回答