`
rensanning
  • 浏览: 3545832 次
  • 性别: Icon_minigender_1
  • 来自: 大连
博客专栏
Efef1dba-f7dd-3931-8a61-8e1c76c3e39f
使用Titanium Mo...
浏览量:38094
Bbab2146-6e1d-3c50-acd6-c8bae29e307d
Cordova 3.x入门...
浏览量:607080
C08766e7-8a33-3f9b-9155-654af05c3484
常用Java开源Libra...
浏览量:682017
77063fb3-0ee7-3bfa-9c72-2a0234ebf83e
搭建 CentOS 6 服...
浏览量:89197
E40e5e76-1f3b-398e-b6a6-dc9cfbb38156
Spring Boot 入...
浏览量:401674
Abe39461-b089-344f-99fa-cdfbddea0e18
基于Spring Secu...
浏览量:69650
66a41a70-fdf0-3dc9-aa31-19b7e8b24672
MQTT入门
浏览量:91645
社区版块
存档分类
最新评论

【转】Appcelerator Cloud Push Notification in iPhone

阅读更多
Push Notification in iOS Using Appcelerator Cloud Service

We can implement Push Notification in iOS using Appcelerator Cloud
  • Service in 5 steps.
  • Cloud User Login
  • Retrieve Device Token
  • Subscribe a Channel
  • Push Certificates
  • Push Configuration

1)Cloud User Login
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


var Cloud = require('ti.cloud');
 
Cloud.Users.login({
    login: 'push123',
    password: 'push123'
}, function (e) {
if (e.success) {
var user = e.users[0];
 alert("Loggin successfully");
    } else {
        alert("Error :"+e.message);
    }
});


2)Retrieve Device Token
You can Retrieve Device Token using below code

Titanium.Network.registerForPushNotifications({
    types: [
        Titanium.Network.NOTIFICATION_TYPE_BADGE,
        Titanium.Network.NOTIFICATION_TYPE_ALERT,
        Titanium.Network.NOTIFICATION_TYPE_SOUND
    ],
success:function(e)
{
    deviceToken = e.deviceToken;
    alert("deviceToken = "+deviceToken);
    registerForPush();
},
error:function(e)
{
    alert("Error: "+e.message);
},
callback:function(e)
{
    alert("push notification received"+JSON.stringify(e.data));
}
});


3)Subscribe a Channel
Add following code for channel subscribtion

Cloud.PushNotifications.subscribe({
    channel: 'demo_alert',
    type:'ios',
    device_token: deviceToken
}, function (e) {
    if (e.success) {
        alert('Success :'+((e.error && e.message) || JSON.stringify(e)));
    } else {
        alert('Error:' + ((e.error && e.message) || JSON.stringify(e)));
    }
});


4)Push Certificates
It is most important part of this Tutotial, Appcelerator Doc clearly expained about how to create push certificates. http://cloud.appcelerator.com/docs/ios#push
Follow this section("Provisioning your Device for specialized Development") to create Development and Production Push certificates. Your certificates should be in .p12 format.

5)Push Configuration
After getting the push certificates(in my case I have created development push certificate), upload it in cloud console. 
My Apps -> Manage ACS ->  DEVELOPMENT ->  Settings -> Apple iOS Push Certificates


Cool.., You have completed  Push Notification setup. This time for testing, run the application in iOS device and click the button "REGISTER PUSH NOTIFICATION". You will get 3 alerts continuously.

Then go to My Apps -> Manage ACS -> DEVELOPMENT -> Push Notifications, here you can see "1 iOS 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 iOS device(with default icon and sound)


Push Notification in iPad


Push Notification Callback

Here you can download the complete working project from my Github Appcelerator Titanium iOS Push Notification

原文:这里
  • 大小: 16 KB
  • 大小: 16.9 KB
  • 大小: 20.9 KB
  • 大小: 96 KB
  • 大小: 65.2 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics