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>...
[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) ☆ 出版信息:☆ [作者信息] ...
In this book you'll learn how to take your existing web knowledge, and adjust your thinking to make the shift from the browser to native mobile app. Table of Contents Chapter 1 Meet the Appcelerator...
#Appcelerator Titanium Alloy Mobile - ... ######Android Push - 安装 Android 推送模块 可以从这里下载,我们仅将其用于 Android Parse 推送连接 ######Pull 刷新 - 安装模块 [ gittio install nl.fokkezb.pullTo
钛碎片模块 此模块为 Appcelerator Titanium 应用程序添加了 Android Fragments 支持 贡献者 Nimrod Kobelkowsky (@nborracha) 合法的
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...
NULL 博文链接:https://eonbell.iteye.com/blog/853810
适用于Android Google Play许可的Appcelerator Titanium模块 关于Google Play许可 当您将Android应用程序发布到Google Play时,没有防止阻止将APK复制到其他未许可设备的保护措施。 如果您的应用正常发布,则很容易...
NULL 博文链接:https://rensanning.iteye.com/blog/1463904
Atom-atom-appcelerator-titanium.zip,用于atom文本编辑器的appcelerator开发工具和ui包原子加速器钛包,atom是一个用web技术构建的开源文本编辑器。
该模块可以在您的 Titanium 项目中选择,同时兼容 iOS 和 Android 平台。 该模块公开了一个方法 .getConnectionType() ,该方法返回一个带有网络类型名称的字符串。 可能的名称有无、未知、未知网络、未知移动、...
titanium-appcelerator-progress-view, 在 Titanium Appcelerator项目中,要使用的自定义进度视图 进度视图这是一个进度视图,显示你的应用程序的某些状态。 你可以设置加载,成功和错误状态。只使用三行代码,你就...