亚马逊AWS如何订阅端点,以SNS的话题? [英] AMAZON AWS How do i subscribe an endpoint to SNS topic?

查看:713
本文介绍了亚马逊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.

我正在学习亚马逊的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?

推荐答案

有没有办法为自动订阅一个端点的话题,但你可以通过code完成所有。

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

您可以直接调用订阅 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 code,创建一个端点,并预订主题:

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;
}];

请务必 SNS已授予访问权限:订阅在Cognito的角色,让你的应用程序,使这个电话

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

更新2015年7月8日:更新,以反映AWS的iOS SDK 2.2.0 +

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

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

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