AWSのSNSを用いてPUSH通知を実装しようと思っているのですが、
AWSのSNSのダッシュボードでの"enable"がfalseになってしまいPUSHが遅れません。
php
1 public function testPush(){ 2 $my_id = 4;//Pushを送信するユーザーのID 3 $user_id_array = [3,6];//Pushを受け取るユーザーのID 4 $my_name = $this->getUser($my_id);//ユーザーの名前を取得する関数 5 foreach($user_id_array as $user_id){ 6 //DBに保存した各ユーザーのデバイストークンを取得する。 7 $device_token = $this->getToken($user_id); 8 9 $user_name = $this->getUser($user_id); 10 if($device_token != null && $user_name != null){ 11 12 $msg = "$user_name".'さん'."$my_name".'さんよりメッセージが届いています。'; 13 14 $this->PushTo->PushSNS($msg,$device_token); 15 } 16 } 17 }
php
1 //PUSH通知を送信 2 public function pushSNS($msg,$device_token){ 3 $sns = SnsClient::factory(array( 4 'credentials' => array( 5 //アクセスのための公開鍵と秘密鍵を指定 6 'key' => '************', 7 'secret' => '************', 8 ), 9 'region' => 'ap-northeast-1', // AP_NORTHEAST_1はtokyo region 10 'version' => '2010-03-31', 11 )); 12 13 //アプリケーションを指定(Application ARN:Amazon SNS上に表記されている) 14 //Product 15 $iOS_AppArn = 'arn:aws:sns:ap-northeast-1:****************'; 16 $iOS_model = $sns->listEndpointsByPlatformApplication(array( 17 'PlatformApplicationArn' => "$iOS_AppArn", 18 )); 19 20 //通知メッセージ 21 $alert = $msg; 22 // それぞれのエンドポイントへメッセージを送る 23 foreach ($iOS_model['Endpoints'] as $endpoint){ 24 $endpointArn = $endpoint['EndpointArn']; 25 $enable = $endpoint['Attributes']['Enabled']; 26 $endpoint_device_token =$endpoint['Attributes']['Token']; 27 if($device_token == $endpoint_device_token){ 28 if($enable == true){ 29 $content = array( 30 'TargetArn' => $endpointArn, 31 'MessageStructure' => 'json', 32 'Message' => json_encode(array( 33 'APNS' => json_encode(array( 34 'aps' => array( 35 'alert' => $alert, 36 'sound' => 'default', 37 'badge' => 1 38 ), 39 //カスタム可能 40 'transition_index' => 3,//1:Atab 2:Btab 3:Ctab 4:Dtabへの遷移に適宜カスタムする。 41 )) 42 )) 43 ); 44 try{ 45 $sns->publish($content); 46 //return true; 47 }catch (Exception $e){ 48 print($e->getMessage()); 49 } 50 }elseif($enable == false){ 51 echo 'bud'; 52 } 53 } 54 } 55 return 0; 56 }
DBにはユーザーIDが3と6のデバイストークンは保存されていて、
片方(ID3のユーザー)にPush通知を送ることはできていますが、
もう片方に送信できません。
ダッシュボードで確認すると送信できていない方のトークンの"enable"が"false"になってしまっていました。
一時的に"enable"を"false"にしても、再度Pushを試すと元に戻ってPushも送れていない状態になってしまいます。
なにかありましたら、随時補足させていただきますので、
よろしくお願い致します。
参考サイト
http://noumenon-th.net/webstrategy/2015/06/09/amazonsns/

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。