Hussein Hussein - 3 months ago 24
Objective-C Question

iOS: Trigger push notification from app programatically using Amazon SNS

Is there any code which clarifies how to send push notifications to a device directly from code, knowing that I am using

Amazon SNS
, such that the push notification is triggered from the app?

I added all devices data to
SNS console
(token..), and couldn't find any clear document which resolved this issue.


I found a solution:

AWSSNS *publishCall = [AWSSNS defaultSNS];

AWSSNSPublishInput *message = [AWSSNSPublishInput new];

message.subject = @"My First Message";

//This is the ending point
message.targetArn = @"arn:aws:sns:eu-west-X:xxxxxxxxx:endpoint/APNS_SANDBOX/AmazonTest/aaaaaaaa-aaaa-aaaaaa-aaaaaa";
message.subject =@"hello";
message.message =self.textField.text;
//    message.messageAttributes = messageDict;
//    message.messageStructure = jsonString;
if ([self.textField.text isEqualToString:@""]) {

[publishCall publish:message completionHandler:^(AWSSNSPublishResponse * _Nullable response, NSError * _Nullable error) {
    if(error) NSLog(@"%@", [error userInfo]);
    if(response) NSLog(@"%@", [response description]);