欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【转】Appcelerator Cloud Push Notification in iPhone

程序员文章站 2022-05-24 16:14:38
...
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
【转】Appcelerator Cloud Push Notification in iPhone
            
    
    博客分类: Titanium appceleratortitaniumACSpushiphone 

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
            
    
    博客分类: Titanium appceleratortitaniumACSpushiphone 

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"
【转】Appcelerator Cloud Push Notification in iPhone
            
    
    博客分类: Titanium appceleratortitaniumACSpushiphone 

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
            
    
    博客分类: Titanium appceleratortitaniumACSpushiphone 
Push Notification in iPad

【转】Appcelerator Cloud Push Notification in iPhone
            
    
    博客分类: Titanium appceleratortitaniumACSpushiphone 
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
            
    
    博客分类: Titanium appceleratortitaniumACSpushiphone 
  • 大小: 16 KB
  • 【转】Appcelerator Cloud Push Notification in iPhone
            
    
    博客分类: Titanium appceleratortitaniumACSpushiphone 
  • 大小: 16.9 KB
  • 【转】Appcelerator Cloud Push Notification in iPhone
            
    
    博客分类: Titanium appceleratortitaniumACSpushiphone 
  • 大小: 20.9 KB
  • 【转】Appcelerator Cloud Push Notification in iPhone
            
    
    博客分类: Titanium appceleratortitaniumACSpushiphone 
  • 大小: 96 KB
  • 【转】Appcelerator Cloud Push Notification in iPhone
            
    
    博客分类: Titanium appceleratortitaniumACSpushiphone 
  • 大小: 65.2 KB