[color=orange][b]Push Notification in iOS Using Appcelerator Cloud Service[/b][/color]
We can implement Push Notification in iOS using Appcelerator Cloud [list][*]Service in 5 steps.
[*]Cloud User Login
[*]Retrieve Device Token
[*]Subscribe a Channel
[*]Push Certificates
[*]Push Configuration[/list]
[color=orange]1)Cloud User Login[/color]
Create a test user in Appcelerator Cloud Console
[b]My Apps -> Manage ACS -> DEVELOPMENT -> Users[/b]
and login with credential. Use below code for cloud user login
[img]http://dl.iteye.com/upload/attachment/0070/6371/0e5c612e-89b4-3603-acbb-d6d6ad6e81a5.png[/img]
[color=orange]2)Retrieve Device Token[/color]
You can Retrieve Device Token using below code
[color=orange]3)Subscribe a Channel[/color]
Add following code for channel subscribtion
[color=orange]4)Push Certificates[/color]
It is most important part of this Tutotial, Appcelerator Doc clearly expained about how to create push certificates. [url=http://cloud.appcelerator.com/docs/ios#push]http://cloud.appcelerator.com/docs/ios#push[/url]
Follow this section("[b]Provisioning your Device for specialized Development[/b]") to create Development and Production Push certificates. Your certificates should be in .p12 format.
[color=orange]5)Push Configuration[/color]
After getting the push certificates(in my case I have created development push certificate), upload it in cloud console.
[b]My Apps -> Manage ACS -> DEVELOPMENT -> Settings -> Apple iOS Push Certificates[/b]
[img]http://dl.iteye.com/upload/attachment/0070/6373/df8146c8-d53d-3104-b867-98b4b70a806d.png[/img]
Cool.., You have completed Push Notification setup. This time for testing, run the application in iOS device and click the button "[b]REGISTER PUSH NOTIFICATION[/b]". You will get 3 alerts continuously.
Then go to M[b]y Apps -> Manage ACS -> DEVELOPMENT -> Push Notifications[/b], here you can see "[b]1 iOS clients subscribed to push notifications[/b]"
[img]http://dl.iteye.com/upload/attachment/0070/6375/3a2d39e8-5529-3494-93a1-16347a6a7782.png[/img]
It is time to send push notification, enter the values and hit the button "[b]Send Push Notification[/b]" instantly you will receive notification in your iOS device(with default icon and sound)
[img]http://dl.iteye.com/upload/attachment/0070/6377/268d10db-e391-3763-bd82-4f1bda236432.png[/img]
Push Notification in iPad
[img]http://dl.iteye.com/upload/attachment/0070/6379/2eb2ef40-a308-3d29-8960-1518f153d30f.png[/img]
Push Notification Callback
Here you can download the complete working project from my Github [url=https://github.com/railskarthi/acs_ios_push]Appcelerator Titanium iOS Push Notification[/url]
原文:[url=http://www.titaniumtutorial.com/2012/07/appcelerator-cloud-push-notification-in.html]这里[/url]
We can implement Push Notification in iOS using Appcelerator Cloud [list][*]Service in 5 steps.
[*]Cloud User Login
[*]Retrieve Device Token
[*]Subscribe a Channel
[*]Push Certificates
[*]Push Configuration[/list]
[color=orange]1)Cloud User Login[/color]
Create a test user in Appcelerator Cloud Console
[b]My Apps -> Manage ACS -> DEVELOPMENT -> Users[/b]
and login with credential. Use below code for cloud user login
[img]http://dl.iteye.com/upload/attachment/0070/6371/0e5c612e-89b4-3603-acbb-d6d6ad6e81a5.png[/img]
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);
}
});
[color=orange]2)Retrieve Device Token[/color]
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));
}
});
[color=orange]3)Subscribe a Channel[/color]
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)));
}
});
[color=orange]4)Push Certificates[/color]
It is most important part of this Tutotial, Appcelerator Doc clearly expained about how to create push certificates. [url=http://cloud.appcelerator.com/docs/ios#push]http://cloud.appcelerator.com/docs/ios#push[/url]
Follow this section("[b]Provisioning your Device for specialized Development[/b]") to create Development and Production Push certificates. Your certificates should be in .p12 format.
[color=orange]5)Push Configuration[/color]
After getting the push certificates(in my case I have created development push certificate), upload it in cloud console.
[b]My Apps -> Manage ACS -> DEVELOPMENT -> Settings -> Apple iOS Push Certificates[/b]
[img]http://dl.iteye.com/upload/attachment/0070/6373/df8146c8-d53d-3104-b867-98b4b70a806d.png[/img]
Cool.., You have completed Push Notification setup. This time for testing, run the application in iOS device and click the button "[b]REGISTER PUSH NOTIFICATION[/b]". You will get 3 alerts continuously.
Then go to M[b]y Apps -> Manage ACS -> DEVELOPMENT -> Push Notifications[/b], here you can see "[b]1 iOS clients subscribed to push notifications[/b]"
[img]http://dl.iteye.com/upload/attachment/0070/6375/3a2d39e8-5529-3494-93a1-16347a6a7782.png[/img]
It is time to send push notification, enter the values and hit the button "[b]Send Push Notification[/b]" instantly you will receive notification in your iOS device(with default icon and sound)
[img]http://dl.iteye.com/upload/attachment/0070/6377/268d10db-e391-3763-bd82-4f1bda236432.png[/img]
Push Notification in iPad
[img]http://dl.iteye.com/upload/attachment/0070/6379/2eb2ef40-a308-3d29-8960-1518f153d30f.png[/img]
Push Notification Callback
Here you can download the complete working project from my Github [url=https://github.com/railskarthi/acs_ios_push]Appcelerator Titanium iOS Push Notification[/url]
原文:[url=http://www.titaniumtutorial.com/2012/07/appcelerator-cloud-push-notification-in.html]这里[/url]