Does Azure Notification Hub Support iOS VoIP Push Notifications?

Naresh Khuriwal 20 Reputation points
2024-11-15T14:28:02.5466667+00:00

I am using the paid service of Azure Notification Hub to send regular push notifications and VoIP push notifications. Regular push notifications are working fine for both Android and iOS. However, VoIP push notifications are not functioning on iOS.

I have updated the required payload and header parameters according to the documentation, but the notifications are still being sent as normal messages instead of VoIP messages.

For Android, VoIP push notifications are working as expected.

Could someone confirm if Azure Notification Hub supports iOS VoIP push notifications? If yes, are there specific configurations or steps I need to follow to enable it?

Azure Notification Hubs
Azure Notification Hubs
An Azure service that is used to send push notifications to all major platforms from the cloud or on-premises environments.
334 questions
Azure Event Hubs
Azure Event Hubs
An Azure real-time data ingestion service.
663 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Shree Hima Bindu Maganti 1,600 Reputation points Microsoft Vendor
    2024-11-18T08:42:11.9966667+00:00

    Hi @Naresh Khuriwal ,
    Welcome to the Microsoft Q&A Platform!
    Azure Notification Hub does support iOS VoIP push notifications, but certain specific configurations are required to ensure they are sent correctly.
    APNs VoIP Certificate

    Use a VoIP-specific APNs certificate generated from the Apple Developer portal.

    • Upload the .p12 file to Azure Notification Hub.
    • Include content-available: 1 in the payload to indicate background processing.
        {
            "aps": {
                "content-available": 1,
                "alert": {
                    "title": "Incoming Call",
                    "body": "You have an incoming call."
                }
            }
        }
      

    Headers

    Set the following headers:

    • apns-push-type: voip
    • apns-priority: 10
    • apns-topic: <Bundle Identifier>.voip

    Bundle Identifier

    Ensure the app’s Bundle Identifier matches the apns-topic.

    Device Token:

    • Use a VoIP-specific device token generated with
    pushRegistry.desiredPushTypes = [.voIP]
    

    Test with APNs

    • Use tools like curl to test VoIP push notifications directly with APNs.

    Azure Notification Hub Logs

    • Enable and review diagnostic logs in the Azure portal for errors or mismatches.
      If the answer is helpful, please click "Accept Answer" and kindly upvote it.

  2. Naresh Khuriwal 20 Reputation points
    2024-11-29T02:38:14.8466667+00:00
    
    // Check if form data is received
    if (isset($_REQUEST['tag'])) {
        $tag = htmlspecialchars(trim($_REQUEST['tag'])); // Sanitize input
        $client_type = htmlspecialchars(trim($_REQUEST['client_type'])); // Sanitize input
    
        $is_voip_push = true; // Set to true for VOIP push
        // $client_type = "FcmV1"; // Platform type (e.g., FcmV1, apple, etc.)
    
        // Prepare notification details
        $title = "New Alert";
        $body = "You have a new update. Please check your app for details.";
        $uuid = Uuid::uuid4();
        // Convert the UUID to string and remove hyphens
        $message_id = str_replace('-', '', $uuid->toString());
    
        if($client_type == "android"){
            $payload = json_encode([
                "notification" => [
                    "title" => $title,
                    "body" => $body,
                ],
                "android" => [
                    "priority" => "high" // Example custom data
                ]
            ]);
        }
        if($client_type == "apple"){
           
            $aps = [
                "content-available" => 1,
                "alert" => [
                    "title" => $title,
                    "body" => $body
                ]
            ];
    
            
            $payload = json_encode([
                "aps" => $aps
            ]);
    
    
        }
        
    
        // Instantiate NotificationHub
        try {
            $notificationHub = new NotificationHub($connectionString, $hubName);
            echo $payload;
            echo "\n";
    
            // Create Notification object
            $notification = new Notification($client_type, $payload);
    
            // Send Notification
            $message_id = $notificationHub->sendNotification($notification, $tag, $is_voip_push, $client_type);
    
            // Log result
            if ($message_id) {
                echo "Notification sent successfully! Message ID: $message_id\n";
            } else {
                echo "Failed to send notification.\n";
            }
        } catch (Exception $e) {
            echo "Error sending notification: " . $e->getMessage() . "\n";
        }
    }
    
    
    
    

    Main Sending Method

    
    	public function sendNotification($notification, $tagsOrTagExpression, $is_voip_push, $client_type) 
    	{
    		if (is_array($tagsOrTagExpression)) {
    			$tagExpression = implode(" || ", $tagsOrTagExpression);
    		} else {
    			$tagExpression = $tagsOrTagExpression;
    		}
    		# build uri
    		$uri = $this->endpoint . $this->hubPath . "/messages" . NotificationHub::API_VERSION;
    		//$url = "https://fcm.googleapis.com/fcm/send";
    		// $GLOBALS['log']->info("apiv2:NotificationHub:info:" . ' uri: ' . $uri);
    		$message_id = null;
    		$ch = curl_init($uri);
    
    		if (in_array($notification->format, ["template", "apple", "fcm", "gcm", "FcmV1", "adm"])) {
    			$contentType = "application/json;charset=utf-8";
    		} else {
    			$contentType = "application/xml";
    		}
    
    		$token = $this->generateSasToken($uri);
    
    		$headers = [
    		    'Authorization: '.$token,
    		    'Content-Type: '.$contentType,
    		    'ServiceBusNotification-Format: '.$notification->format
    		];
    
            if ("" !== $tagExpression) {
    			$headers[] = 'ServiceBusNotification-Tags:' .$tagExpression; #;
    		}
    
    		if ($is_voip_push && ($client_type == "apple" || $client_type == "iphone") ) {
    			$headers[] = 'ServiceBusNotification-Apns-Push-Type: voip';
    			$headers[] = 'ServiceBusNotification-Apns-Topic: com.messaging.stars.voip';
    			$headers[] = 'ServiceBusNotification-Apns-Priority: 10';
    			$headers[] = 'ServiceBusNotification-Apns-Expiration: 0';		
    			$GLOBALS['log']->info("apiv2:NotificationHub:Headers of sending notificaiton:" . json_encode($headers));
    			print_r($headers);
    		}
    
    		# add headers for other platforms
    		if (is_array($notification->headers)) {
    			$headers = array_merge($headers, $notification->headers);
    		}
    		curl_setopt_array($ch, array(
    		    CURLOPT_POST => TRUE,
    		    CURLOPT_RETURNTRANSFER => TRUE,
    		    CURLOPT_SSL_VERIFYPEER => FALSE,
    		    CURLOPT_HTTPHEADER => $headers,
    		    CURLOPT_POSTFIELDS => $notification->payload,
    			CURLOPT_HEADER => TRUE, // Include headers in the output
    			CURLOPT_VERBOSE => TRUE
    		));
            curl_setopt($ch, CURLOPT_VERBOSE, true);
    		$response = curl_exec($ch);
    		// Check for errors
    		if($response === FALSE){
    			$GLOBALS['log']->info("apiv2:NotificationHub:Error sending notificaiton:" . curl_error($ch));
    		    return;
    		}
    
    		$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
    		$header = substr($response, 0, $header_size);
    		$body = substr($response, $header_size);
    	
    		$info = curl_getinfo($ch);
    		$GLOBALS['log']->info("apiv2:NotificationHub:status_code:" . $info['http_code'] . ' msg: ' . $body);
    		$GLOBALS['log']->info("apiv2:NotificationHub:info: headers: " . $header);
    
    		
    		if ($info['http_code'] <> 201) {
    			$GLOBALS['log']->info("apiv2:NotificationHub:Error sending notificaiton:" . $info['http_code'] . ' msg: ' . $response);
    			return;
    		}
    
    		// Extract Location header
    		$headers_array = explode("\r\n", $header);
    		$location_header = null;
    		foreach ($headers_array as $header_line) {
    			if (stripos($header_line, 'Location:') === 0) {
    				$location_header = trim(substr($header_line, 9));
    				break;
    			}
    		}
    		try{
    			$parsed_url = parse_url($location_header);
    			$path = $parsed_url['path'];
    			$path_segments = explode('/', $path);
    			$message_id = end($path_segments);
    		}catch (Exception $e) {
    			$GLOBALS['log']->info("apiv2:NotificationHub:error: " . $e->getMessage());
    			return;
    		}
    		
    		return $message_id;
    	} 
    

    Registration Request

    <?xml version="1.0" encoding="utf-8"?>
    <entry xmlns="http://www.w3.org/2005/Atom">
        <content type="application/xml">
            <AppleRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
                xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
                <Tags>keith51330_20241128132110</Tags>
                <DeviceToken>---replaced value --XXXX</DeviceToken>
            </AppleRegistrationDescription>
        </content>
    </entry>
    

    Registration Response

    <entry p1:etag="W/&quot;1&quot;" xmlns:p1="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
        <id>https://xx.notificationhub.windows.net/xx-01/registrations/3722865485130199588-5427083653015844075-1?api-version=2015-01</id>
        <title type="text">3722865485130199588-5427083653015844075-1</title>
        <published>2024-11-28T07:51:18Z</published>
        <updated>2024-11-28T07:51:18Z</updated>
        <link rel="self" href="https://xxx.windows.net/xx-01/registrations/3722865485130199588-5427083653015844075-1?api-version=2015-01" />
        <content type="application/xml">
            <AppleRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
                <ETag>1</ETag>
                <ExpirationTime>9999-12-31T23:59:59.9999999</ExpirationTime>
                <RegistrationId>3722865485130199588-5427083653015844075-1</RegistrationId>
                <Tags>keith51330_20241128132110</Tags>
                <DeviceToken>xxx</DeviceToken>
            </AppleRegistrationDescription>
        </content>
    </entry>
    

    This is the last try please let me suggest if i am doing anything wrong Normal push is working but voip push is not working


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.