使用Amazon SNS的推送通知 - 设备ID

问题描述:

使用Xamarin Forms开发移动应用程序。对于推送通知,我们使用亚马逊简单通知服务(SNS)。使用Amazon SNS的推送通知 - 设备ID

Xamarin.Andriod: 1.在安装该应用程序,我们使用了下面的代码段要注册的设备ID到亚马逊SNS中MainActivity的onCreate方法。它工作正常

using (Intent intent = new Intent("com.google.android.c2dm.intent.REGISTER")) 
       { 
        string senders = AmazonUtils.GoogleConsoleProjectId; 
        intent.SetPackage("com.google.android.gsf"); 
        intent.PutExtra("app", PendingIntent.GetBroadcast(this, 0, new Intent(), 0)); 
        intent.PutExtra("sender", senders); 
        this.StartService(intent); 
       } 
  1. 当应用打开检查相应的设备ID在亚马逊SNS中注册每一次。由于此应用程序需要额外的4秒来检查此过程,并在该页面加载之后。

  2. 我们是否需要在应用程序每次打开时检查设备是否注册?这是推送通知的标准吗?

  3. 问候, 基兰

开始=“2”>

安装Xam.Plugins.Settings

这将添加一个名为Settings

一个辅助类,在这个类中你应该增加:

private const string IsRegisteredKey = "registered_key"; 
private static readonly bool IsRegisteredDefault = false; 

//Then adding this property 
public static bool IsRegistered 
{ 
    get 
    { 
     return AppSettings.GetValueOrDefault(IsRegisteredKey, IsRegisteredDefault); 
    } 
    set 
    { 
     AppSettings.AddOrUpdateValue(IsRegisteredKey, value); 
    } 
} 

然后在你的代码调用此属性,像这样:

using YourProjectNameSpace.Droid.Helper 

.... 

if(!Settings.IsRegistered) 
{ 
    using (Intent intent = new Intent("com.google.android.c2dm.intent.REGISTER")) 
    { 
     string senders = AmazonUtils.GoogleConsoleProjectId; 
     intent.SetPackage("com.google.android.gsf"); 
     intent.PutExtra("app", PendingIntent.GetBroadcast(this, 0, new Intent(), 0)); 
     intent.PutExtra("sender", senders); 
     this.StartService(intent); 
    } 
    Settings.IsRegistered = true; 
}