简体   繁体   English

在钛中推送通知

[英]push notifications in titanium

I nedd to create push notifications for my app that works on Android and IOS. 我需要为可在Android和IOS上运行的应用程序创建推送通知。 I have read the docomention but can't figure out how to puth this to work. 我已经阅读了docomention,但不知道如何解决这个问题。

Hase someone an exmaple code that works that can show it to me so I can see how it works? 向某人散发一个可以正常工作的示例代码,该代码可以向我展示,以便我了解其工作原理? I have tried this on IOS: 我已经在IOS上尝试过:

var deviceToken; var deviceToken;

Titanium.Network.registerForPushNotifications({
    success : function(e) {
        deviceToken = e.deviceToken;
        alert("deviceToken = " + deviceToken);
        //subscribeToChannel();
    },
    error : function(e) {
        alert("Error: " + e.message);
    },
    callback : function(e) {
        alert("deviceToken = " + deviceToken);
        //recebePush(e.data);
    }
});

But the success, error pr callback functions ar never fired. 但是成功,错误的PR回调函数从未触发过。

In Android I tried this: 在Android中,我尝试了以下操作:

// 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;
}
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);
});

But it returns always an error saying: "Failed to register for push notifications! INVALID_SENDER. 但是它总是返回一条错误消息:“未能注册推送通知!INVALID_SENDER。

I have generated an GCM API Key and GCM sender ID for android an created the certificate for IOS but it does no work 我已经为Android生成了GCM API密钥和GCM发送者ID,并为IOS创建了证书,但是它没有任何作用

You can find complete step by step guides for configuring push notification service from here 您可以从此处找到配置推送通知服务的完整分步指南

And you can get complete guide for get device token and subscribe device for push notification with example From Here 您可以从此处获得示例获取设备令牌的完整指南以及为推送通知订阅设备

Have you registered your GCM API Key / Sender ID and your APNS certificate with the Appcelerator Platform (in the menu under Apps > YOURAPP > Arrow > Push Notifications). 您是否已在Appcelerator平台(在“应用程序> YOURAPP>箭头>推送通知”下的菜单中)注册了GCM API密钥/发件人ID和APNS证书。

You need to register those credentials with Appcelerator, and you need to enable Appcelerator Platform Services for your app in Appcelerator Studio. 您需要在Appcelerator中注册这些凭据,并且需要在Appcelerator Studio中为您的应用启用Appcelerator Platform Services。 You should see something like this in your tiapp.xml: 您应该在tiapp.xml中看到以下内容:

<property name="acs-authbase-url" type="string">https://secure-identity.cloud.appcelerator.com</property>
<property name="acs-base-url" type="string">https://api.cloud.appcelerator.com</property>
<property name="acs-push-api-url" type="string">https://api.cloud.appcelerator.com/v1/</property>
<property name="acs-api-key-production" type="string">xxxxxxxxxxxxxx</property>
<property name="acs-api-key-development" type="string">xxxxxxxxxxxxxx</property>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM