【问题标题】:Push Notification using Amazon SNS – Device id使用 Amazon SNS 的推送通知 – 设备 ID
【发布时间】:2017-10-24 13:17:05
【问题描述】:

使用 Xamarin 表单开发移动应用程序。对于推送通知,我们使用 Amazon Simple Notification Service (SNS)。

Xamarin.Andriod: 1. 在安装应用程序时,我们使用以下代码 sn-p 在 MainActivity 的 OnCreate 方法中将设备 ID 注册到 Amazon SNS。效果很好

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 是否已在 Amazon SNS 中注册。由于这个应用程序需要额外的 4 秒来检查这个过程,并且在该页面加载之后。

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

问候, 切兰

【问题讨论】:

    标签: xamarin push-notification xamarin.forms xamarin.android amazon-sns


    【解决方案1】:

    安装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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多