Find Jobs
Hire Freelancers

Adjust OneSignal PHP function to open URLs in App

$10-30 USD

Concluído
Publicado há quase 4 anos

$10-30 USD

Pago na entrega
Hello, I have a news website based on Wordpress, and I created a Webview App, for android and Apple using those kits ([login to view URL]). When I send push notification using Wordpress OneSignal plugin ([login to view URL]), and a user open the notification, the URL open in browser instead of App. After reading the documentation of OneSignal ([login to view URL]), in the section : Sending Notifications To Both Web Browsers And Mobile Devices The documentation propose to, Create a PHP file and upload it to directory contect/mu-plugins. I did this, now when the user click on the mobile notification, the App open, but displaying the home page instead of the URL. This is the PHP file content : <?php add_filter('onesignal_send_notification', 'onesignal_send_notification_filter', 10, 4); function onesignal_send_notification_filter($fields, $new_status, $old_status, $post) { /* Goal: We don't want to modify the original $fields array, because we want the original web push notification to go out unmodified. However, we want to send an additional notification to Android and iOS devices with an additionalData property. * */ $fields_dup = $fields; $fields_dup['isAndroid'] = true; $fields_dup['isIos'] = true; $fields_dup['isAnyWeb'] = true; $fields_dup['isWP'] = false; $fields_dup['isAdm'] = false; $fields_dup['isChrome'] = false; // $fields_dup['android_channel_id'] = "<CHANNEL ID UUID HERE>"; $fields_dup['data'] = array("myappurl" => $fields['url']); /* Important to set web_url to support opening through both mobile and browser*/ $fields_dup['web_url'] = $fields_dup['url']; /* Important to unset the URL to prevent opening the browser when the notification is clicked for mobile app users */ unset($fields_dup['url']); $onesignal_post_url = "[login to view URL]"; /* Hopefully OneSignal::get_onesignal_settings(); can be called outside of the plugin */ $onesignal_wp_settings = OneSignal::get_onesignal_settings(); $onesignal_auth_key = $onesignal_wp_settings['app_rest_api_key']; $request = array("headers" => array("content-type" => "application/json;charset=utf-8", "Authorization" => "Basic " . $onesignal_auth_key), "body" => json_encode($fields_dup), "timeout" => 60); $response = wp_remote_post($onesignal_post_url, $request); if (is_wp_error($response) || !is_array($response) || !isset($response['body'])) { $status = $response->get_error_code(); $error_message = $response->get_error_message(); error_log("There was a " . $status . " error returned from OneSignal when sending to mobile users: " . $error_message); return; } return $fields; } ?>
ID do Projeto: 26038242

Sobre o projeto

1 proposta
Projeto remoto
Ativo há 4 anos

Quer ganhar algum dinheiro?

Benefícios de ofertar no Freelancer

Defina seu orçamento e seu prazo
Seja pago pelo seu trabalho
Descreva sua proposta
É grátis para se inscrever e fazer ofertas em trabalhos
Concedido a:
Avatar do Usuário
hi I've experienced in both android and web development..so ping me I'll do it all and make sure it works fine...(budget negotiable)
$25 USD em 10 dias
4,7 (29 avaliações)
3,7
3,7

Sobre o cliente

Bandeira do(a) LEBANON
Beirut, Lebanon
5,0
29
Método de pagamento verificado
Membro desde mai. 13, 2012

Verificação do Cliente

Obrigado! Te enviamos um link por e-mail para que você possa reivindicar seu crédito gratuito.
Algo deu errado ao enviar seu e-mail. Por favor, tente novamente.
Usuários Registrados Total de Trabalhos Publicados
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Carregando pré-visualização
Permissão concedida para Geolocalização.
Sua sessão expirou e você foi desconectado. Por favor, faça login novamente.