我的Tizen推送消息服务请求已被批准。但是,当我去注册推送服务时,它会通过向控制台输出状态为“未注册”来进行响应。该应用程序本身将作为可穿戴式Web应用程序运行,目前正在Tizen的可穿戴模拟器上进行测试。它可以使用AJAX正常工作并更新SQL数据库,但是Tizen的推送通知和推送API通常难以实现。我尝试过发布到Tizen论坛,但是这些论坛大多数都是韩文的,我看不到可以在哪里发布。我需要知道通过可穿戴模拟器上运行的Web应用程序成功注册并将通知推送到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
答案 0 :(得分:0)
我认为这是特权问题 除了功能之外,您还需要在清单中声明特权。
<privilege name="http://tizen.org/privilege/push"</privilege>
希望这会有所帮助。