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
Appcelerator Cloud Push Notification in iPhone_第1张图片

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 M y Apps -> Manage ACS -> DEVELOPMENT -> Push Notifications, here you can see " 1 iOS clients subscribed to push notifications"
Appcelerator Cloud Push Notification in iPhone_第2张图片

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)

Appcelerator Cloud Push Notification in iPhone_第3张图片
Push Notification in iPad

Appcelerator Cloud Push Notification in iPhone_第4张图片
Push Notification Callback

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

原文: 这里
  • Appcelerator Cloud Push Notification in iPhone_第5张图片
  • 大小: 16 KB
  • Appcelerator Cloud Push Notification in iPhone_第6张图片
  • 大小: 16.9 KB
  • Appcelerator Cloud Push Notification in iPhone_第7张图片
  • 大小: 20.9 KB
  • Appcelerator Cloud Push Notification in iPhone_第8张图片
  • 大小: 96 KB
  • Appcelerator Cloud Push Notification in iPhone_第9张图片
  • 大小: 65.2 KB
  • 查看图片附件

你可能感兴趣的:(appcelerator,titanium,ACS,push,iphone)