【发布时间】:2019-03-15 14:36:01
【问题描述】:
我需要有关 App Center 推送通知的帮助。我想知道用户是否在他的 iOS/Android 设备上启用或禁用了推送通知。此任务应在应用程序启动时完成。我按照此 App Center 教程进行操作,但在检查推送通知是否启用或禁用时收到错误消息。
错误 CS4033:“等待”运算符只能在异步中使用 方法。考虑用'async'修饰符标记这个方法和 将其返回类型更改为“任务”。
怎么了?如何确定用户是否启用或禁用了推送通知?
using Foundation;
using UIKit;
using Microsoft.AppCenter;
using Microsoft.AppCenter.Analytics;
using Microsoft.AppCenter.Crashes;
using Microsoft.AppCenter.Push;
namespace iosprojectnew.iOS
{
[Register("AppDelegate")]
class Program : UIApplicationDelegate
{
private static Game1 game;
internal static void RunGame()
{
game = new Game1();
game.Run();
}
static void Main(string[] args)
{
UIApplication.Main(args, null, "AppDelegate");
}
public override void FinishedLaunching(UIApplication app)
{
if (!AppCenter.Configured)
{
bool isEnabled = await Push.IsEnabledAsync();
Push.PushNotificationReceived += (sender, e) =>
{
// Add the notification message and title to the message
var summary = $"Push notification received:" +
$"\n\tNotification title: {e.Title}" +
$"\n\tMessage: {e.Message}";
// If there is custom data associated with the notification,
// print the entries
if (e.CustomData != null)
{
summary += "\n\tCustom data:\n";
foreach (var key in e.CustomData.Keys)
{
summary += $"\t\t{key} : {e.CustomData[key]}\n";
}
}
// Send the notification summary to debug output
System.Diagnostics.Debug.WriteLine(summary);
};
}
AppCenter.Start("...", typeof(Analytics), typeof(Crashes), typeof(Push));
RunGame();
}
}
}
【问题讨论】:
标签: c# xamarin.android xamarin.ios monogame visual-studio-app-center