Provider向APNS发送消息可以参考javapns中NotificationTest.java。也可以参考如下例子。
  (1)使客户端图标显示数字标记
  Push.badge(2, keystore, password, false, "7bb8d508e32df651c6c239439737dbd40a88d2461ad2ac1e5dbe49ecea5ccc67");
  其中,2为要显示的数字;
  String keystore = "PushCertificates.p12";     //P12文件的路径;
  String password = "sosoimage";                //P12文件的密码;
  false,指的是使用测试环境,使用正式产品环境应传入true.
  "7bb8d508e32df651c6c239439737dbd40a88d2461ad2ac1e5dbe49ecea5ccc67"为客户端获得并传给Provider的DeviceToken,此参数还可以传入String[]对象,以同时向多个客户端Push消息。
  (2)使客户端显示横幅或提醒
  Provider可以向客户端Push一条Message,但客户端有权限决定这条Message的显示方式(无、横幅、提醒)。
  Push.alert("A Message", keystore, password, )false, "7bb8d508e32df651c6c239439737dbd40a88d2461ad2ac1e5dbe49ecea5ccc67");
  (3)混合方式
  可以在一个Push消息里附带多种信息,Message, 标记,声音,可以使用如下代码.
  PushNotificationPayload payload = PushNotificationPayload.complex();
  payload.addAlert("A Message");
  payload.addBadge(2);
  payload.addSound("test.aiff");
  Push.payload(payload, , keystore, password, false, "7bb8d508e32df651c6c239439737dbd40a88d2461ad2ac1e5dbe49ecea5ccc67");
  上面的代码都有可能会有相应的Exception抛出来,需要处理。更多的使用方式可以参考 http://code.google.com/p/javapns/
  IOS客户端接收处理由APNS发来的消息
  (1)当程序未启动,用户接收到消息。需要在AppDelegate中的didFinishLaunchingWithOptions得到消息内容。代码如下,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
NSDictionary* payload = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (payload)
{
...
}
...
}
  (2)当程序在前台运行,接收到消息不会有消息提示(提示框或横幅)。当程序运行在后台,接收到消息会有消息提示,点击消息后进入程序,AppDelegate的didReceiveRemoteNotification函数会被调用(需要自己重写),消息做为此函数的参数传入,代码如下
  - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)payload
  {
  ...
  }
  (3)无论在哪个函数传入,消息总是一个NSDictionary对象,处理方式可以参考如下代码
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)payload
{
NSLog(@"remote notification: %@",[payload description]);
NSString* alertStr = nil;
NSDictionary *apsInfo = [payload objectForKey:@"aps"];
NSObject *alert = [apsInfo objectForKey:@"alert"];
if ([alert isKindOfClass:[NSString class]])
{
alertStr = (NSString*)alert;
}
else if ([alert isKindOfClass:[NSDictionary class]])
{
NSDictionary* alertDict = (NSDictionary*)alert;
alertStr = [alertDict objectForKey:@"body"];
}
application.applicationIconBadgeNumber = [[apsInfo objectForKey:@"badge"] integerValue];
if ([application applicationState] == UIApplicationStateActive && alertStr != nil)
{
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Pushed Message" message:alertStr delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
}