gpt4 book ai didi

ruby - 如何查看移动设备是否已注册

转载 作者:数据小太阳 更新时间:2023-10-29 06:53:27 25 4
gpt4 key购买 nike

我正在使用适用于 Amazon SNS 的 Amazon AWS Ruby SDK,但我在使用已注册的设备时遇到了一些问题。有时,当设备再次注册时,我会收到类似 AWS::SNS::Errors::InvalidParameter Invalid parameter: Token Reason: Endpoint arn:aws:sns:us-east-1:**** already exists 这样的错误具有相同的 Token,但具有不同的属性。。如何检查端点是否已存在,更重要的是,如何获取给定 token 的端点?

最佳答案

感谢 BvdBijl 的想法,我做了一个扩展方法来删除现有的,如果找到,然后添加它。

using System;
using System.Text.RegularExpressions;
using Amazon.SimpleNotificationService;
using Amazon.SimpleNotificationService.Model;

namespace Amazon.SimpleNotificationService
{
public static class AmazonSimpleNotificationServiceClientExtensions
{
private const string existingEndpointRegexString = "Reason: Endpoint (.+) already exists with the same Token";
private static Regex existingEndpointRegex = new Regex(existingEndpointRegexString);
public static CreatePlatformEndpointResponse CreatePlatformEndpointIdempotent(
this AmazonSimpleNotificationServiceClient client,
CreatePlatformEndpointRequest request)
{
try
{
var result = client.CreatePlatformEndpoint(request);
return result;
}
catch (AmazonSimpleNotificationServiceException e)
{
if (e.ErrorCode == "InvalidParameter")
{
var match = existingEndpointRegex.Match(e.Message);
if (match.Success) {
string arn = match.Groups[1].Value;
client.DeleteEndpoint(new DeleteEndpointRequest
{
EndpointArn = arn,
});
return client.CreatePlatformEndpoint(request);
}
}
throw;
}
}
}
}

关于ruby - 如何查看移动设备是否已注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19551067/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com