#!/usr/bin/perl

use Net::APNS::Persistent;
use URI::Escape;

  #my $devicetoken_hex = 'AF571DEF64C7BCDCE0AC07995101D08DCF1EF53ABDACA300F96120EFDC70FF8E'; #Iphone 5 blanco

  $texto = $ARGV[0];
  #$texto =~ s/%20/ /g;
  my $devicetoken_hex = $ARGV[1];
  open (OUTFILE, ">/tmp/pruebacgi") || die "No se puedo crear el archivo";
  print OUTFILE "$texto\n";
  my $apns = Net::APNS::Persistent->new({
    sandbox => 1,
    #host    => 'gateway.push.apple.com',
    cert    => 'isladev.pem',
    key     => 'isladev.pem',
    passwd  => 'sistemas',
  });

  $apns->queue_notification(
    $devicetoken_hex,
    {
      aps => {
          alert => "$texto",
          sound => 'default',
          badge => 1,
      },
    });

  $apns->send_queue;

  $apns->disconnect;


