Help us understand the problem. What is going on with this article?

RubyスクリプトとAWSのSNSで複数デバイスへのpush通知

More than 3 years have passed since last update.

これが出来ると何が嬉しいの?

一括メッセージ設定、一括送信の自動化が出来ます!

前提条件

Ruby環境

gem install aws-sdk-coreを実施済みであること

iOS環境

AWS SNSでアプリを作成済みであること
AWS SNSへエンドポイントを自動登録出来る実装が完了していること
AWS SDKを導入済みであること

上記の内容は以下のサイトが参考になります!

http://www.aguuu.com/archives/2013/09/amazon-sns-mobile-push-ios-push-notification/

http://www.lancork.net/2013/08/how-to-ios-push-first/

http://www.lancork.net/2013/08/how-to-ios-push-second/

http://www.slideshare.net/shimy_net/amazon-sns-mobile-push

http://www.slideshare.net/AmazonWebServicesJapan/aws-31275003

https://github.com/awslabs/aws-sdk-ios-samples/tree/master/SNS-MobileAnalytics-Sample/Swift/

概要図

スクリーンショット 2014-11-28 19.01.58.png

・流れ1:アプリ起動時にAWS SNSのアプリ側にデバイストークンを登録
・流れ2:対象のSNSからエンドポイントを取得
・流れ3:作成済みのTopicに取得したエンドポイントをSubscribeする
・流れ4:アプリに対してメッセージをpushし、即時に通知

Rubyスクリプト

sample.rb

require 'aws-sdk'

sns = AWS::SNS.new(
  :access_key_id => 'YOUR_ACCESS_KEY',
  :secret_access_key => 'YOUR_SECRET_ACCESS_KEY',
  :region => 'us-east-1')
client = sns.client

# 対象のSNSからエンドポイントを取得
num = client.list_endpoints_by_platform_application(platform_application_arn: 'arn:aws:sns:us-east-1:************:app/APNS_SANDBOX/DevelopAppPush')

# 作成済みのTopicに取得したエンドポイントをSubscribeする
num.endpoints.each{|value|
  client.subscribe(
    topic_arn: 'arn:aws:sns:us-east-1:************:test_topic',
    protocol: 'application',
    endpoint: value.endpoint_arn)
}

# 起動していないアプリに対してメッセージをpush通知
response = client.publish(
  target_arn: 'arn:aws:sns:us-east-1:************:test_topic',
  message: 'push通知のテスト成功'
  )



備考

AWSドキュメント
http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/SNS/Client.html#create_platform_endpoint-instance_method

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした