使用SSL证书,这个就涉及不同的服务器不同的配置了,例如windows/linux的SSL连接socket的如何实现?
逻辑条件判断需要发送的消息,简单一点就是每10min发送一条
组合每条message的payload/ 按照一定的格式,其实格式也不是很多种
断开与apns的链接
Device token
定位符号,APNS首先为每一个程序分配了一token,然后你的服务器要记录所有安装此app的token。token看起来是这样的:
c9d4c07c fbbc26d6 ef87a44d 53e16983 1096a5d5 fd825475 56659ddd f715defc
HTTP API call,在app启动的时候,我们调用必要的方法,并且注册到我们的服务service上面,这样用户/设备和token就关联了/
====客户端的测试工作,当没有服务器端业务,甚至服务器没有,也可以进行以下测试,单也要真机
//when the application successfully registers with Apple Push Service (APS)....
-(void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSLog(@"My token:%@",deviceToken);
/*
token:<2d0938f4 f6feb164 a5ca07d6 1e8c043c fc7ee6df 49eb9afd 47d3515f 4b27ab19>
*/
}
-(void) application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"failed to get token, error:%@",error);
}
if([launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) { //if we're here, apps was launched due to Remote Notification }
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]]autorelease];
// Override point for customization after application launch.
self.viewController = [[[flyViewControlleralloc]initWithNibName:@"flyViewController"bundle:nil]autorelease];
self.window.rootViewController =self.viewController;
[self.windowmakeKeyAndVisible];
//let the device know we want to recieve push notifications
[[UIApplicationsharedApplication]registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound) ];
//你的程序可以用以下代码了解什么类型的推送通知,我们知道:
/*
UIRemoteNotificationType enabledTypes=[[UIApplication sharedApplication] enabledRemoteNotificationTypes];
NSLog(@"%@",enabledTypes);
*/
//模拟器不支持push notification
returnYES;
}
Welcome to the JavaPNS project, home of the most user-friendly, powerful and fine-tuned Java library for APNS! This fully-featured Java library allows developers to push notifications to iOS devices (iPhone, iPod, iPad, etc.) through the Apple Push Notification Service using a simple yet powerful set of tools. First-time users will find the library to be extremely easy to use (start with a single line of code!), while advanced users will benefit from the library's flexible design and scalability features.
How to build an Apple Push Notification provider server (tutorial)
http://blog.serverdensity.com/2009/07/10/how-to-build-an-apple-push-notification-provider-server-tutorial/
http://maniacdev.com/2010/02/feature-rich-push-notification-server/
網上已有不少網頁介紹自設Notification Server的詳細方法,然而,筆者認為以下書本的介紹更詳盡:
iPhone Advanced Projects by Dylan Bruzenak
書本第10章有講述相關之詳細方法。
然而,筆者認為架設Notification Server其實是頗麻煩的,因為:
以上的東東,筆者曾做過,做是做得到,但有一定的Development及Maintenance成本。
Urban Airship公司提供了AirMail Push服務,大大簡化了自設Notification server的程序,你可以使用其server作為你自已的server與Apple server之中間人:用Urban Airship server去管理用家的Token,用其server去發出Notification。因此你可以不用自設數據庫去管理用家的Token。
AirMail Push提供一系列簡易的API(比起自已架設Server去發Notification,AirMail API是簡易多了)供你使用,使你免去架設Socket connection之苦。API是HTTP Request,絕大部份Hosting都容許HTTP request。
然而,這是一項收費服務,Urban Airship提供了幾個收費模式。假如使用其Indie收費模式,每月首250,000個Notification是免費的(其後$0.0005/message)(筆者於2010-10-15更新:Indie收費已由「每月首250,000Notification免費改為每月首1,000,000Notification免費,詳情請參考其收費模式)。
如果你有大量用戶,又或者要經常發出大量push notification予用家(例如新聞App),不妨自設Notification server。