I am getting an issue with sound in push notification
Using Ionic 4 and Angular 8 to creating android app
My code to send Push in PHP
<?php
error_reporting(E_ALL);
ini_set("display_errors", true);
// prep the bundle
$msg = array
(
'message' => $_POST['message'],
'title' => $_POST['title'],
'subtitle' => $_POST['subtitle'],
'tickerText' => $_POST['ticket_text'],
'vibrate' => 1,
'alert'=> 'true',
'badge'=> true,
'sound'=> 'true',
'largeIcon' => 'large_icon',
'smallIcon' => 'small_icon'
);
$fields = array
(
'registration_ids' => $registrationIds,
'data' => $msg
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
and the config.xml file for android platform
<platform name="android">
<resource-file src="resources/android/push.mp3" target="res/push.mp3" />
</platform>
Related
Below is my code to create or update subscription in Mailchimp.
function mailchimp_ajax_subscription()
{
$data = isset( $_POST['formData'] ) ? $_POST['formData'] : array();
ob_start();
if(count($data) > 0)
{
$api_key = 'XXXXXXXXXXXXXX';
$status = 'unsubscribed'; // subscribed, unsubscribed, cleaned, pending
$args = array(
'method' => 'PUT',
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( 'user:'. $api_key )
),
'body' => json_encode(array(
'email_address' => $data["email"],
'status' => $status,
'tags' => array($data["name"])
))
);
$response = wp_remote_post( 'https://' . substr($api_key,strpos($api_key,'-')+1) . '.api.mailchimp.com/3.0/lists/XXXXX/members/' . md5(strtolower($email)), $args );
$body = json_decode( $response['body'] );
if ( $response['response']['code'] == 200 && $body->status == $status ) {
echo 'The user has been successfully ' . $status . '.';
} else {
echo '<b>' . $response['response']['code'] . $body->title . ':</b> ' . $body->detail;
}
}
wp_die();
}
Using above code, I can create subscription into Mailchimp but If I enter same email to edit the tags/status it gives me error.
Error:
400Member Exists: abc#xyz.com is already a list member. Use PUT to
insert or update list members.
I already used PUT in the code so what is missing?
You can use TAGS API to update the TAGS. Below is the sample code to update the TAG:
$postdata = array(
'apikey' => $api_key,
'email_address' => $userData["email"],
'tags' => array(
array(
'name' => $userData["name"],
'status' => 'active'
),
)
);
$mch_api = curl_init(); // initialize cURL connection
curl_setopt($mch_api, CURLOPT_URL, 'https://' . substr($api_key,strpos($api_key,'-')+1) . '.api.mailchimp.com/3.0/lists/' . $list_id . '/members/' . md5(strtolower($userData['email']))."/tags");
curl_setopt($mch_api, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Basic '.base64_encode( 'user:'.$api_key )));
curl_setopt($mch_api, CURLOPT_RETURNTRANSFER, true); // return the API response
curl_setopt($mch_api, CURLOPT_TIMEOUT, 10);
curl_setopt($mch_api, CURLOPT_POST, true);
curl_setopt($mch_api, CURLOPT_POSTFIELDS, json_encode($postdata) ); // send data in json
$result = curl_exec($mch_api);
I want upload image using api on my page so any tell me how i do it?
Now i work with this api
http://localhost/test_project/wp-json/wp/v2/media
but it's doesn't help me for upload image on page or post.
I use wordpress json api plugin.
You can do using following code. Here I have use wp_handle_upload.
$param = array('search' => 'XXXXXXXX');
$imagetype = array(
'bmp' => 'image/bmp',
'gif' => 'image/gif',
'jpe' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'png' => 'image/png',
'tif' => 'image/tiff',
'tiff' => 'image/tiff'
);
$override = array(
'mimes' => $imagetype,
'test_form' => false
);
$upload_file = wp_handle_upload( $_FILES['YOUR_UPLOAD_FILE_NAME'], $override );
remove_filter( 'upload_dir', array($this, 'change_upload_dir') );
if ( isset( $upload['error'] ) ){
// DO ACTION ACCORDINGLY
} else {
// File is uploaded successfully.
$uploaded_file_url = $upload_file['url'];
$uploaded_file_name = basename($upload_file['url']);
}
Simple PHP FireBase (FCM) script showing how to send an Android push notification . Be sure to replace the $apikey with a proper one from the Google API's Console page.
<?php
#API access key from Google API's Console
$apikey= 'YOUR-SERVER-API-ACCESS-KEY-GOES-HERE';
$registrationIds = $_GET['id'];
#prep the bundle
$msg = array
(
'body' => 'Body Of Notification',
'title' => 'Title Of Notification',
'icon' => 'myicon',/*Default Icon*/
'sound' => 'mySound'/*Default sound*/
);
$fields = array
(
'to' => $registrationIds,
'notification' => $msg
);
$headers = array
(
'Authorization: key=' . $apikey,
'Content-Type: application/json'
);
#Send Reponse To FireBase Server
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
#Echo Result Of FireBase Server
echo $result;
We are using this type code in wordpress plugins creating time but is not working.
$data = array(
'0' => array('Name'=> 'user1', 'Status' =>'complete', 'Priority'=>'Low', 'Salary'=>'001'),
'1' => array('Name'=> 'user2', 'Status' =>'inprogress', 'Priority'=>'Low', 'Salary'=>'111'),
'2' => array('Name'=> 'user3', 'Status' =>'hold', 'Priority'=>'Low', 'Salary'=>'333'),
'3' => array('Name'=> 'user4', 'Status' =>'pending', 'Priority'=>'Low', 'Salary'=>'444'),
'4' => array('Name'=> 'user5', 'Status' =>'pending', 'Priority'=>'Low', 'Salary'=>'777'),
'5' => array('Name'=> 'user6', 'Status' =>'pending', 'Priority'=>'Low', 'Salary'=>'777')
);
this type array manage and then
$filename = "exportpin".time().".csv";
$fp = fopen('php://output', 'w');
$header = array('name','Status', 'Priority','Salary');
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename='.$filename);
fputcsv($fp, $header);
foreach($item_array as $datas) {
fputcsv($fp, $datas);
}
exit;
this type error get
Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\pinrotate\wp-includes\formatting.php:4596)
how do I get my app (Android and iOS) receive push notifications, automatically from a control panel, or a webservice ... the only way I found is at the Appcelerator panel, and is not automatic ...
I wish, for example, when there was an update in the database, the push appeared in the user's mobile phone in question ... how can you do this?
Another thing is that how can I do that is generic for android and ios? Is there any module or video lesson to teach to do that?
For Multi Push Module
This is an part of my php for multi-platform push firing.
// iOS
$apnsHost = 'gateway.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'apns-prod.pem';
//
$abrirPush = 1;
$mensagem = array(
"id_push" => $id_push,
"id_empresa" => $id_empresa,
"abrir" => $abrirPush
);
$mensagem = json_encode($mensagem);
$arr['aps'] = array(
'alert' => $nome_empresa . ' tem uma mensagem para você' ,
'badge' => 1,
'sound' => 'default',
'body' => $mensagem
);
$payload = json_encode($arr);
// Abre Conexão iOS
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
// Android
$arrayAndroid = Array();
// Search for iOS or Android Device
for ($i = 0; $i < count($montaArray); $i++){
$pegaToken = $montaArray[$i];
$contaToken = strlen($pegaToken);
if ($contaToken < 70){
$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $montaArray[$i])) . chr(0) . chr(strlen($payload)) . $payload;
fwrite($apns, $apnsMessage);
}else{
/// PUSH ANDROI ////
array_push( $arrayAndroid, $montaArray[$i]);
}
}
fclose($apns);
// API access key from Google API's Console ( Server KEY )
define( 'API_ACCESS_KEY', 'KEY_HERE' );
// prep the bundle
$msg = array
(
'message' => 'Tem uma mensagem para você',
'title' => $nome_empresa,
'payload' => $mensagem,
'vibrate' => 1,
'sound' => 1,
'largeIcon' => 'large_icon',
'smallIcon' => 'small_icon'
);
$fields = array
(
'registration_ids' => $arrayAndroid,
'data' => $msg
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
print $result;
curl_close( $ch );
note that Apple doesn't alloy an array of tokens like Google does. As Android's token are larger than iOS's Tokens, I count it length to know which token it is.
$montaArray comes from my database where all token are stored