MAUI 中的 Azure 通知中心

问题描述 投票:0回答:2

如何在MAUI中实现azure通知中心?

我尝试按照 xamarin(link) 演练进行操作,但包不被接受并且显示错误

Unexpected failure of task "VerifyVersionsTask"

.net maui azure-notificationhub .net-7.0
2个回答
0
投票

1) 在 microsoft 教程 仅安装

Xamarin.Azure.NotificationHubs.Android

2) 在 MainActivty.cs 示例中

public class MainActivity : MauiAppCompatActivity
{
    const string CONNECTION_STRING = "Endpo";
    const string HUB_NAME = "n";
    protected override void OnCreate(Bundle savedInstanceState)
    {
        FirebaseApp.InitializeApp(this);
        base.OnCreate(savedInstanceState);
        // Listen for push notifications
        WindowsAzure.Messaging.NotificationHubs.NotificationHub.SetListener(new NotificationListener());

        // Start the SDK
        WindowsAzure.Messaging.NotificationHubs.NotificationHub.Start(this.Application, HUB_NAME, CONNECTION_STRING);
        HandleIntent(Intent);
        CreateNotificationChannelIfNeeded();
    }

    protected override void OnNewIntent(Intent intent)
    {
        base.OnNewIntent(intent);
        HandleIntent(intent);
    }

    private static void HandleIntent(Intent intent)
    {
        FirebaseCloudMessagingImplementation.OnNewIntent(intent);
    }

    private void CreateNotificationChannelIfNeeded()
    {
        if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
        {
            CreateNotificationChannel();
        }
    }

    private void CreateNotificationChannel()
    {
        var channelId = $"{PackageName}.general";
        var notificationManager = (NotificationManager)GetSystemService(NotificationService);
        var channel = new NotificationChannel(channelId, "General", NotificationImportance.Default);
        notificationManager.CreateNotificationChannel(channel);
        FirebaseCloudMessagingImplementation.ChannelId = channelId;
        //FirebaseCloudMessagingImplementation.SmallIconRef = Resource.Drawable.ic_push_small;
    }
}

public partial class NotificationListener : Java.Lang.Object, INotificationListener
{
    void INotificationListener.OnPushNotificationReceived(Context context, INotificationMessage message)
    {
        //Push Notification arrived - print out the keys/values
        var data = message.Data;
        if (data != null)
        {
            foreach (var entity in data)
            {
                Android.Util.Log.Debug("AZURE-NOTIFICATION-HUBS", "Key: {0}, Value: {1}", entity.Key, entity.Value);
            }
        }
    }
}

0
投票

我在这里尝试了其他答案,但按照教程无法进行设置。不过,我确实做了一些工作,并拼凑了一些类似于使用 Azure 通知中心并显示本地通知的教程的内容。如果有人想尝试并做出更多贡献,该项目就在这里https://github.com/Xcelerator-Group/dotnet-maui-notifications。不知道为什么 MS 不提供带有工作示例的 GitHub 存储库!!

© www.soinside.com 2019 - 2024. All rights reserved.