【发布时间】:2016-11-01 13:09:12
【问题描述】:
我正在尝试在 Xamarin 表单中使用 Azure 的通知中心实现推送通知。目前我正在使用 GCM 为 Android 执行此操作,我关注 this link。但是在“向 droid 项目中添加推送通知”教程的第 5 步中,我收到了modifier static is not valid for this item 的错误。在这一步之后,这就是我的代码的样子:
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Create a new instance field for this activity.
static MainActivity instance = null;
// Set the current instance of MainActivity.
instance = this;
global::Xamarin.Forms.Forms.Init (this, bundle);
Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();
LoadApplication (new App ());
try
{
// Check to ensure everything's setup right
GcmClient.CheckDevice(this);
GcmClient.CheckManifest(this);
// Register for push notifications
System.Diagnostics.Debug.WriteLine("Registering...");
GcmClient.Register(this, PushHandlerBroadcastReceiver.SENDER_IDS);
}
catch (Java.Net.MalformedURLException)
{
CreateAndShowDialog("There was an error creating the Mobile Service. Verify the URL", "Error");
}
catch (Exception e)
{
CreateAndShowDialog(e.Message, "Error");
}
private void CreateAndShowDialog(String message, String title)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.SetMessage(message);
builder.SetTitle(title);
builder.Create().Show();
}
// Return the current activity instance.
public static MainActivity CurrentActivity
{
get
{
return instance;
}
}
}
我是 C# 和 Xamarin 表单的新手,不知道哪里出错了。
【问题讨论】:
-
请学习基本的 C# 语法...这似乎是编译时错误(这意味着您不了解 C# 基础知识),它准确地告诉您哪里出了问题以及在哪一行...
标签: c# android azure xamarin.android xamarin.forms