Push notification 在没有appcelaretor云服务的情况下,有没有发送推送通知的方法?
我已经知道如何使用钛合金发送推送通知,我的做法是:Push notification 在没有appcelaretor云服务的情况下,有没有发送推送通知的方法?,push-notification,titanium,Push Notification,Titanium,我已经知道如何使用钛合金发送推送通知,我的做法是: // Require the module var CloudPush = require('ti.cloudpush'); var deviceToken = null; // Initialize the module CloudPush.retrieveDeviceToken({ success: deviceTokenSuccess, error: dev
// Require the module
var CloudPush = require('ti.cloudpush');
var deviceToken = null;
// Initialize the module
CloudPush.retrieveDeviceToken({
success: deviceTokenSuccess,
error: deviceTokenError
});
// Enable push notifications for this device
// Save the device token for subsequent API calls
function deviceTokenSuccess(e) {
deviceToken = e.deviceToken;
// alert("--->" + deviceToken);
subscribeToChannel();
}
function deviceTokenError(e) {
alert('Failed to register for push notifications! ' + e.error);
}
// Process incoming push notifications
CloudPush.addEventListener('callback', function (evt) {
alert("Notification received: " + evt.payload);
});
// For this example to work, you need to get the device token. See the previous section.
// You also need an ACS user account.
// Require in the Cloud module
var Cloud = require("ti.cloud");
function loginUser(){
// Log in to ACS
Cloud.Users.login({
login: 'example',
password: 'example'
}, function (e) {
if (e.success) {
alert('Login successful');
} else {
alert('Error:\n' +
((e.error && e.message) || JSON.stringify(e)));
}
});
}
function subscribeToChannel(){
// Subscribe the user and device to the 'test' channel
// Specify the push type as either 'android' for Android or 'ios' for iOS
// Check if logged in:
Cloud.PushNotifications.subscribe({
channel: 'test',
//device_token: 'APA91bHRjGoZLCYKwn-XcCtNLETuf-KRKfT4sMgVE4KgXQgInYfZuYTNrZC7FUMugLs0idzzqtLytrvVJjVzYBzQoc7Q81hEerq0O2vww_tV8mACuUfAi0JRvs7LoufnQZpYLZrb_1rlUsIOEMsPxDs9b_pIRJF5rw',
device_token:deviceToken,
type: Ti.Platform.name == 'android' ? 'android' : 'ios'
}, function (e) {
if (e.success) {
alert('Subscribed');
} else {
alert('Error:\n' +
((e.error && e.message) || JSON.stringify(e)));
}
});
}
function unsubscribeToChannel (){
// Unsubscribes the user and device from the 'test' channel
Cloud.PushNotifications.unsubscribe({
channel: 'test',
device_token: deviceToken
}, function (e) {
if (e.success) {
alert('Unsubscribed');
} else {
alert('Error:\n' +
((e.error && e.message) || JSON.stringify(e)));
}
});
}
loginUser();
但是,这种方式仅用于通过这种手动方式发送推送通知,因为需要您编写警报并在该后端站点中按下按钮
所以我的问题是:有没有办法从自己的服务器以“自动”的方式发送钛合金推送通知
提前感谢您的帮助。是的,这是可能的
有关如何获取推送通知的设备令牌的说明,请参见
要发送通知,必须将令牌发送到服务器。然后,服务器将您的通知发送到Apple推送通知服务(APNS)。见苹果文档。这不是“自动”的,但对于PHP或任何其他语言来说都是一项简单的任务——您可以找到很多脚本
您还可以安排本地通知,根据您的情况,这些通知可能会派上用场。感谢您的回答,我将更仔细地阅读文档,然后我将在PHP中搜索一个简单的任务,我认为在PHP中配置此类服务更容易。类似的问题