What is Push Notification?
Push notification allows an app to notify you of new messages or events without the need to actually open the application, similar to how a text message will make a sound and pop up on your screen. This is a great way for apps to interact with us in the background, whether it be a game notifying us of some event occurring in our game world or simply the iPad's mail application beeping as a new message appears in our inbox.
read more
Push Notification in Titanium Using Cloud Service
We can achieve Push Notification in Titanium using Appcelerator Cloud
- Service in 5 steps.
- Cloudpush Module Implementation
- Retrieve Device Token
- Cloud User Login
- Subscribe a Channel
- Push Configuration
1)Cloudpush Module Implementation
Cloudpush provides methods for accessing Android push notifications from ACS using the MQTT protocol. require cloudpush in your app and add module in your tiapp.xml
// add this line in tiapp.xml
<module platform="android">ti.cloudpush</module>
// add this line in app.js
var CloudPush = require('ti.cloudpush');
2)Retrieve Device Token
You can Retrieve Device Token using below code
CloudPush.retrieveDeviceToken({
success: function deviceTokenSuccess(e) {
alert('Device Token: ' + e.deviceToken);
deviceToken = e.deviceToken
},
error: function deviceTokenError(e) {
alert('Failed to register for push! ' + e.error);
}
});
3)Cloud User Login
Before subscribe for Push Notification, cloud user should logged in.
So create a test user in Appcelerator Cloud Console
My Apps -> Manage ACS -> DEVELOPMENT -> Users
and login with credential. Use below code for cloud user login
Cloud.Users.login({
login: 'push123',
password: 'push123'
}, function (e) {
if (e.success) {
alert("login success");
} else {
alert('Error: ' +((e.error && e.message) || JSON.stringify(e)));
}
});
4)Subscribe a Channel
Add following code for channel subscribtion
Cloud.PushNotifications.subscribe({
channel: 'alert', // "alert" is channel name
device_token: deviceToken,
type: 'android'
}, function (e){
if (e.success) {
alert('Subscribed for Push Notification!');
}else{
alert('Error:' +((e.error && e.message) || JSON.stringify(e)));
}
});
5)Android Push Configuration
It is final step. In Appcelerator Cloud Console go to
My Apps -> Manage ACS -> DEVELOPMENT -> Settings/Android Push Configuration and enter the Application Package in the text box. Your pakage name should be similar to com.xxx.androidpush Here xxx is company name and androidpush is Application name
Cool.., You have completed Android Push Notification setup(
Here is the whole sample code). This time for testing, run the application in android device and click the button "
Android Cloud Push Notification". You will get 3 alerts continuously.
Then go to
My Apps -> Manage ACS -> DEVELOPMENT -> Push Notifications, here you can see "
1 Android clients subscribed to push notifications"
It is time to send push notification, enter the values and hit the button "Send Push Notification" instantly you will receive notification in your Android device(with default icon and sound)
How to customize ACS Push notification?
Here you can use use your custom sounds and icons.
Icon
custom icons must be placed in below directory
App_root/platform/android/res/drawable/myicon.png
Here "myicon.png" is custom icon, specified in the push message without the filename extension. For example: in icon text box enter the file name without extension(myicon)
Sound
Custom icons must be placed in below directory
App_root/Resources/sound/beep.wav
Here "beep.wav" is custom sound, specified in the push message with the filename extension. For example: in Sound/Custom/beep.wav enter custom sound filename in the text box(with extension). Here is the screens of custom notification
Here you can download the complete working project from my Github
Appcelerator Titanium Android Push Notification.
原文:
这里
- 大小: 41 KB
- 大小: 16 KB
- 大小: 9.4 KB
- 大小: 27.3 KB
- 大小: 42.2 KB
- 大小: 57.5 KB
分享到:
相关推荐
Appcelerator-Cloud-REST-SDK 一个帮助程序类,使您可以轻松地使用REST... 使用Cloud#api()方法例子: $ ACS -> api ( "/push_notification/notify" , "POST" , array ( "channel" => "free_channel" , "payload" =
红混 一个有趣且友好的 Appcelerator Cloud MBaaS 命令行。安装$ [sudo] npm install redmix -g用法获取所有可用的命令和选项: $ redmix help:wine_glass: Redmix « A fun and friendly Appcelerator Cloud MBaaS ...
这里的概念旨在作为我在 Appcelerator Alloy 和 Appcelerator Cloud Services 一书中涵盖的概念的介绍性指南 ##### 这个 repo 的目的是提供一个应用程序模板作为在 Appcelerator Platform 上构建原生、跨平台、支持...
安卓上下文Appcelerator Titanium 代码在 Android 中触发暂停/恢复事件。如何使用将 Context.js 放在您的app/lib文件夹中,并使用 Android Context 注册每个活动: <Alloy><Window xss=removed xss=removed></Alloy>...
标题“Appcelerator:调查显示安卓平台对开发者吸引力逐渐减弱”揭示了一个重要的趋势,即在2012年第一季度,Android平台对于开发者的吸引力可能正在下降。Appcelerator是一家提供跨平台移动应用开发工具的公司,它...
[Packt Publishing] Appcelerator Titanium 移动应用开发教程 (英文版) [Packt Publishing] Creating Mobile Apps with Appcelerator Titanium (E-Book) ☆ 图书概要:☆ Develop fully-featured mobile ...
[Packt Publishing] Appcelerator Titanium 商业应用开发经典实例 (英文版) [Packt Publishing] Appcelerator Titanium Business Application Development Cookbook (E-Book) ☆ 出版信息:☆ [作者信息] ...
Appcelerator Cloud Services(ACS)则是一个后端即服务(Backend as a Service,简称BaaS)解决方案,它提供了一个简单的API来处理数据存储、推送通知和用户管理等后端功能。ACS的设计初衷是为了减少开发者在创建...
Titanium Appcelerator 是一个开源的移动应用开发平台,它允许开发者使用JavaScript编写原生的iOS、Android和Windows应用。通过Titanium,开发者可以利用一套统一的API来访问各个平台的硬件特性。 组合框(ComboBox...
#Appcelerator Titanium Alloy Mobile - ... ######Android Push - 安装 Android 推送模块 可以从这里下载,我们仅将其用于 Android Parse 推送连接 ######Pull 刷新 - 安装模块 [ gittio install nl.fokkezb.pullTo
钛碎片模块 此模块为 Appcelerator Titanium 应用程序添加了 Android Fragments 支持 贡献者 Nimrod Kobelkowsky (@nborracha) 合法的
Appcelerator Titanium是一个开放源代码的移动应用开发平台,它允许开发者使用JavaScript来创建原生的iOS、Android和Windows应用程序。通过Titanium,开发者可以利用单一的代码库实现跨平台开发,提高开发效率。这个...
Appcelerator 云服务 Titanium Alloy 示例应用程序这里的概念旨在作为我在 Appcelerator Alloy 和 Appcelerator Cloud Services 一书中涵盖的概念的介绍性指南#####这个 repo 的目的是提供一个应用程序模板作为在 ...
这里的概念旨在作为我在 Appcelerator Alloy 和 Appcelerator Cloud Services 一书中涵盖的概念的介绍性指南 ##### ###Getting Started 请通过修改项目的app\lib目录中的文件来设置您的常量 修改下面的代码以使用来
jsca2js, 在Appcelerator格式的JSCA格式中,用于转换JSON的实用工具 jsca2js这个项目提供了一组实用工具来将用 JSCA 规范编写的api转换成JSDoc注释的JavaScript文件。对于 these Titanium ,可以在 ide such / 2或者...
适用于Titanium Appcelerator的Android iBeacon库该项目是Titanium Appcelerator的模块,该模块允许支持Android的Titanium应用程序通过易于使用的Java API与iBeacons进行交互。 可以通知应用程序进入/退出iBeacon...
Appcelerator_test是一个基于JavaScript的项目,主要使用Appcelerator Titanium框架进行开发。Appcelerator Titanium是一个开源的移动应用开发平台,它允许开发者使用JavaScript、HTML、CSS等Web技术来构建原生的iOS...
适用于Android Google Play许可的Appcelerator Titanium模块 关于Google Play许可 当您将Android应用程序发布到Google Play时,没有防止阻止将APK复制到其他未许可设备的保护措施。 如果您的应用正常发布,则很容易...