Мой запрос службы push-сообщений Tizen был одобрен.Однако, когда я иду, чтобы зарегистрироваться в сервисе push, он отвечает, выводя на консоль, что состояние «НЕПРАВИЛЬНО».Само приложение будет работать как носимое веб-приложение и в настоящее время тестируется на носимом эмуляторе Tizen.Он работает и соответствующим образом обновляет базу данных SQL с использованием AJAX, однако реализовать push-уведомления и push-API в целом от Tizen было проблематично.Я пытался публиковать сообщения на форумах Tizen, однако они в основном на корейском языке, и я не вижу, где я могу публиковать сообщения на нем.Мне нужно знать, что еще требуется для успешной регистрации и отправки уведомлений на push-сервер Tizen через веб-приложение, работающее на носимом эмуляторе.Спасибо за ваше время!
##config.xml
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:tizen="http://tizen.org/ns/widgets" id="http://yourdomain/TAUBasicdemo" version="1.0.0" viewmodes="maximized">
<tizen:application id="4MgeHxcwvw.TAUBasicdemo" package="4MgeHxcwvw" required_version="3.0"/>
<tizen:privilege name="http://tizen.org/privilege/push"/>
<tizen:privilege name="http://tizen.org/privilege/notification"/>
<tizen:privilege name="http://www.tizen.org/privileg/internet"/>
<access origin="*" subdomains="true"/>
<content src="index.html"/>
<feature name="http://tizen.org/feature/network.push"/>
<feature name="http://tizen.org/feature/screen.size.normal"/>
<feature name="http://tizen.org/feature/web.service"/>
<feature name="http://tizen.org/feature/watch_app"/>
<feature name="http://tizen.org/feature/web.service"/>
<feature name="http://tizen.org/feature/network.internet"/>
<icon src="icon.png"/>
<name>TAUBasicdemo</name>
<tizen:profile name="wearable"/>
<tizen:setting background-support="disable" encryption="disable" hwkey-event="enable"/>
</widget>
##notification.js
//------------------ NOTIFICATION REGISTRY -----------------------
/*eslint-disable*/
/* Define the error callback */
function errorCallback(response) {console.log('The following error occurred: ' + response.name); }
/* Define the registration success callback */
function registerSuccessCallback(id) { console.log('Registration succeeded with id: ' + id); }
/* Define the state change callback */
function stateChangeCallback(state) {
if (state === 'UNREGISTERED') {
/* Request application registration */
console.log('The state is changed to: ' + state);
tizen.push.register(registerSuccessCallback, errorCallback);
} else if (state === 'REGISTERED') {
/* Gets unread push notifications */
console.log('The state is changed to: ' + state);
tizen.push.getUnreadNotifications();
}
}
//------------------- NOTIFICATION RECEIVING -----------------------
/* Define the notification callback */
function notificationCallback(notification)
{ console.log('A notification arrives.'); }
tizen.push.connect(stateChangeCallback, notificationCallback, errorCallback);
var registrationId = tizen.push.getRegistrationId();
if (registrationId !== null) {
console.log('The registration id: ' + registrationId);}
else { console.log('UNREGISTERED STILL');}
//-----------------HANDLING LAUNCH FROM PUSH SERVICE -----------------------
var requestedAppControl = tizen.application.getCurrentApplication().getRequestedAppControl().appControl;
var pushMessage;
for (var i = 0; i < requestedAppControl.data.length; ++i) {
if (requestedAppControl.data[i].key === 'http://tizen.org/appcontrol/data/push/launch_type') {
/* Launch type is 'registration_change' or 'notification' */
var appData = requestedAppControl.data[i].value[0];
console.log('launch_type: ' + appData);
if (appData === 'registration_change') {
/* Launched due to change in the registration state */
} else if (appData === 'notification') {
/* Launched due to a notification */
try {
/* Retrieve the latest message */
var pushMessage = tizen.push.getPushMessage();
/* Handle the retrieved message */
} catch (error) {
console.log(error.name + ': ' + error.message);
}
}
}
}
//------------MSG RETRIEVE WHEN LAUNCHED FROM PUSH SERVICE ---------
if (pushMessage) {
console.log('notification received on ' + pushMessage.date + ' from: ' + pushMessage.sender);
console.log('Details:');
console.log(' - data: ' + pushMessage.appData);
console.log(' - alert message: ' + pushMessage.alertMessage);
console.log(' - message: ' + pushMessage.message);
console.log(' - session: ' + pushMessage.sessionInfo);
console.log(' - request ID: ' + pushMessage.requestId);
console.log(' - type: ' + pushMessage.type);
}
##index.html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="./lib/tau/mobile/theme/default/tau.css"/>
<meta name="viewport" content="width=device-width,user-scalable=no">
<link rel="stylesheet" href="lib/tau/wearable/theme/default/tau.min.css">
<link rel="stylesheet" media="all and (-tizen-geometric-shape: circle)" href="lib/tau/wearable/theme/default/tau.circle.min.css">
<!-- load theme file for your application -->
<link rel="stylesheet" href="css/style.css">
<script src="lib/tau/wearable/js/tau.min.js"></script>
<script src="js/app.js"></script>
<script type="text/javascript" src="./lib/tau/mobile/js/tau.js"></script>
<script src="js/lowBatteryCheck.js"></script>
<script src="js/circle-helper.js"></script>
<script src="js/notification.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<!-- <div class="ui-page ui-page-active" id="main"> -->
<!-- <header> -->
<!-- <h2 class="ui-title">TAU Basic</h2> -->
<!-- </header> -->
<!-- </div> -->
<button onclick="myFunction()">Click Here!</button>
<p align="center">Start Age Confirmation</p>
<p id="demo"></p>
<script>
function myFunction() {
var txt;
var content = "";
var ofAge_21 = confirm("Is the customer older than 21?");
var file = "http://10.146.3.164/process.php";
if (ofAge_21 == true) {
txt = "Customer OVER 21.";
content = "INSERT INTO age_confirmation_records (Age_Range) VALUES (21)";
} else {
var ofAge_18 = confirm("Are they older than 18?");
if (ofAge_18 == true) {
txt = "Customer BETWEEN 18-21.";
content = "INSERT INTO age_confirmation_records (Age_Range) VALUES (18)";
} else {
txt = "Customer UNDER 18.";
content = "INSERT INTO age_confirmation_records (Age_Range) VALUES (0)";
}
}
alert("CONFIRMED: " + txt);
//POST the SQL command you want to execute to the process.php file
$(document).ready(function() {
$.post(file, { sql_insert: content },
function(data, status) {
alert("Data: " + data + "\nStatus: " + status); }, 'html');
});
}
</script>
</body>
</html>
##output:
The web console logging API (console.log, console.info, console.warn,
console.error) has been disabled.
To activate it, you should launch project with Debug mode.
file:///js/notification.js (34) :UNREGISTERED STILL
file:///js/notification.js (14) :The state is changed to: UNREGISTERED
file:///js/notification.js (4) :The following error occurred: TimeoutError