AMAZON AWS 如何将端点订阅到 SNS 主题? [英] AMAZON AWS How do i subscribe an endpoint to SNS topic?

查看:27
本文介绍了AMAZON AWS 如何将端点订阅到 SNS 主题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Amazon SNS 和 Amazon Cognito 服务在 iOS 应用程序中实施推送通知.Cognito 成功保存令牌,我的应用收到通知,一切正常,但有件事.

I'm implementing push notifications in an iOS app using Amazon SNS and Amazon Cognito services. Cognito saves tokens successfully, my app gets notified, everything's working well, but there is a thing.

现在,当仍在开发中时,我需要手动将端点添加到 SNS 主题,以便所有订阅者都能收到通知.当我将更新推送到 App Store 时,将有数千个令牌要添加.

Now, when still in development, I need to manually add endpoints to an SNS topic, so all subscribers can get notifications. When i'll push an update to the App Store, there will be thousands of tokens to add.

我正在研究 Amazon AWS 文档,但不知道是否有可能在没有额外努力的情况下实现它.

I was studying Amazon AWS documentation, but there was no clue whether it's possible to make it happen without that additional effort.

我的问题:是否可以自动将端点订阅到具有亚马逊服务的主题?

My question: is it possible to automatically subscribe an endpoint to a topic with Amazon services only?

推荐答案

没有办法自动订阅一个端点到一个主题,但你可以通过代码来完成.

There is no way to automatically subscribe an endpoint to a topic, but you can accomplish all through code.

您可以在创建端点后直接调用 Subscribe API.与其他订阅方式不同,SNS 手机推送无需确认.

You can directly call the Subscribe API after you have created your endpoint. Unlike other kinds of subscription, no confirmation is necessary with SNS Mobile Push.

以下是一些创建端点并将其订阅到主题的示例 Objective-C 代码:

Here is some example Objective-C code that creates an endpoint and subscribes it to a topic:

AWSSNS *sns = [AWSSNS defaultSNS];
AWSSNSCreatePlatformEndpointInput *endpointRequest = [AWSSNSCreatePlatformEndpointInput new];
endpointRequest.platformApplicationArn = MY_PLATFORM_ARN;
endpointRequest.token = MY_TOKEN;

[[[sns createPlatformEndpoint:endpointRequest] continueWithSuccessBlock:^id(AWSTask *task) {
    AWSSNSCreateEndpointResponse *response = task.result;

    AWSSNSSubscribeInput *subscribeRequest = [AWSSNSSubscribeInput new];
    subscribeRequest.endpoint = response.endpointArn;
    subscribeRequest.protocols = @"application";
    subscribeRequest.topicArn = MY_TOPIC_ARN;
    return [sns subscribe:subscribeRequest];
}] continueWithBlock:^id(BFTask *task) {
    if (task.cancelled) {
        NSLog(@"Task cancelled");
    }
    else if (task.error) {
        NSLog(@"Error occurred: [%@]", task.error);
    }
    else {
        NSLog(@"Success");
    }
    return nil;
}];

确保您已在 Cognito 角色中授予对 sns:Subscribe 的访问权限,以允许您的应用程序进行此调用.

Make sure you have granted access to sns:Subscribe in your Cognito roles to allow your application to make this call.

2015-07-08 更新:更新以反映 AWS iOS SDK 2.2.0+

Update 2015-07-08: Updated to reflect AWS iOS SDK 2.2.0+

这篇关于AMAZON AWS 如何将端点订阅到 SNS 主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆