Post by c05338 » Sun Jun 18, 2017 8:14 pm

I've developed a code integrated for opencart where the admin is able to send Push Notification to the mobile from the backend via Firebase. So basically I'm trying to send Push Notification through Firebase for both Android and iOS. The code is working well for Android however it's not for iOS as I'm not receiving the push notification. I've created certs in Apple Development Portal and tested the Push Notification from Firebase itself it works like a charm receiving notifications in iOS and Android. However if I try to send it from Opencart it works for Android only.

The Controller code as defined below:

Code: Select all

	protected function sendNotification($notification_id) {
		
		$this->load->model('tool/image');

		$notification_info = $this->db->query("SELECT * FROM ". DB_PREFIX ."mobiapp_notification mn LEFT JOIN ". DB_PREFIX ."mobiapp_notification_description mnd ON (mn.notification_id = mnd.notification_id) WHERE mnd.language_id = '". $this->config->get('config_language_id') ."' AND mn.notification_id = '". $notification_id ."'")->row;
		

		$message = array(					
			'notification_id' => $notification_info['notification_id'],
			'title'		=> $notification_info['title'],
			'link'		=> $notification_info['link'],
			'content'	=> $notification_info['content'],
			'subTitle'	=> strip_tags(html_entity_decode($notification_info['content'])),
			'bannerImage' => $notification_info['image'],
			);

		// Set POST variables
		$gurl = 'https://fcm.googleapis.com/fcm/send';

		$fields = array(
			'to'			=> "/topics/global",
			'time_to_live'	=> 30,
			'notification' => array (
                    'data' => $message,
                    'priority' 		=> 'high',
                    'sound'  => 'default',
            ),
			//'data'			=> $message,
			
			
			'delay_while_idle'	=> true
		);

		$headers = array(
			'Authorization: key=' . $this->config->get('mobiapp_gcm_key'),
			'Content-Type: application/json'
		);

		// Open connection
		$ch = curl_init();

		// Set the url, number of POST vars, POST data
		curl_setopt($ch, CURLOPT_URL, $gurl);

		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

		// Disabling SSL Certificate support temporarly
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

		curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

		// Execute post
		$result = curl_exec($ch);
		if ($result === FALSE) {
			die('Curl failed: ' . curl_error($ch));
		}
		
		// Close connection
		curl_close($ch);

		$this->load->model('mobiapp/notification');

		if (isset(json_decode($result)->message_id)) {
			$message_id = json_decode($result)->message_id;
			$this->model_mobiapp_notification->sendNotification($message_id, $fields, $headers, $error = '');
		} elseif (isset(json_decode($result)->error)) {
			$error = json_decode($result)->error;
			$this->model_mobiapp_notification->sendNotification($message_id = '', $fields, $headers, $error);
		}	
		
	}
And here is the Model Code"

Code: Select all

    public function sendNotification($message_id, $fields, $headers, $error) {
    	$this->db->query("INSERT INTO " . DB_PREFIX . "mobiapp_send SET message_id = '" . $message_id . "', fields = '" . $this->db->escape(serialize($fields)) . "', headers = '" . $this->db->escape(serialize($headers)) . "', error = '" . $error . "'");
    }
I'm not sure if I missed anything so please can you advice and help me how I can resolve this issue I've been stuck for 2 weeks in this task.

Newbie

Posts

Joined
Tue Jan 10, 2012 10:09 pm

Post by bhaspro » Wed Feb 05, 2020 5:30 pm

Were you able to get a solution for the opencart - firebases - iOS push notification ?

Newbie

Posts

Joined
Wed Feb 05, 2020 5:28 pm

Post by Burt65 » Wed Feb 05, 2020 5:41 pm

bhaspro wrote:
Wed Feb 05, 2020 5:30 pm
Were you able to get a solution for the opencart - firebases - iOS push notification ?
Just a suggestion, before posting, check the date of the OP.. (2017)

Over 95% of all computer problems can be traced back to the interface between the keyboard and the chair...


User avatar
Active Member

Posts

Joined
Mon Nov 18, 2013 3:23 pm
Location - Oz

Post by bhaspro » Thu Feb 06, 2020 12:19 am

:) Yes, I saw it earlier.

But no solution was provided, so I was curious about how the problem was fixed. If you have a solution, please share.

We are planning to use this in our app, want to make sure thr are no roadblocks

Newbie

Posts

Joined
Wed Feb 05, 2020 5:28 pm
Who is online

Users browsing this forum: No registered users and 4 guests