How to send APNS Push notifications for iOS Live Activities using Amazon SNS

121 views Asked by At

`This is my Net 7 code, I get success response from Amazon. But the device is not receiving the notification. I am using AWSSDK.Core and AWSSDK.SimpleNotificationService nuget packages

[HttpPost(Name = "SendPushNotification")]
        public async Task<IActionResult> SendPushNotification(string endpoint)
        {
            AmazonSimpleNotificationServiceClient snsClient =
                                    new AmazonSimpleNotificationServiceClient(
                                                amazon_accesskey,
                                                amazon_secret,
                                                RegionEndpoint.USEast1);

            PublishRequest pr = new PublishRequest();
            dynamic jsonmessageIOS = new ExpandoObject();         
            long timestamp = long.Parse(DateTime.Now.AddMinutes(2).ToString("yyyyMMddHHmmss"));

            pr.MessageAttributes = new Dictionary<string, MessageAttributeValue>
            {
                { "AWS.SNS.MOBILE.APNS.TOPIC", new MessageAttributeValue { DataType = "String", StringValue = "com.myapp.push-type.liveactivity" } },
                { "AWS.SNS.MOBILE.APNS.PUSH_TYPE", new MessageAttributeValue { DataType = "String", StringValue = "liveactivity" } },
                { "AWS.SNS.MOBILE.APNS.PRIORITY", new MessageAttributeValue { DataType = "String", StringValue = Convert.ToString(10) } }               
            };

            jsonmessageIOS.APNS = JsonConvert.SerializeObject(new
            {
                aps = new 
                {
                    timestamp = timestamp,
                    @event = "update",
                    contentState = new ContentState { courierName = "John Smith" }
                }
            });

            var jsonIOS = JsonConvert.SerializeObject(jsonmessageIOS);

            pr.Message = jsonIOS;
            pr.MessageStructure = "json";
            pr.TargetArn = endpoint;

            PublishResponse publishResponse = await snsClient.PublishAsync(pr);

            var externalMessageId = publishResponse.MessageId;

            if (publishResponse.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {

                return Ok(new { IsError = false, ExternalMessageId = externalMessageId });
            }

            return BadRequest(new
            {
                IsError = true,
                ResponseStatusCode = publishResponse.HttpStatusCode,
                ResponseSData = publishResponse.ResponseMetadata
            });

        }

Using the above code I am able to send Push notification to device, but ioS live activities are not working. There is no error returned from amazon.If any one has implemented iOS Live activities with AMAZON SNS please advise`

0

There are 0 answers