文章目录
  1. 1. JavaPNS初级使用,关于Push工具类的使用
    1. 1.0.1. JavaPNS初级使用,关于Push工具类的使用

JavaPNS初级使用,关于Push工具类的使用

Ios-javaPns-PushNotificationManager Ios技术文章收录 Ios-iPhone Push

JavaPNS初级使用,关于Push工具类的使用

JavaPNSPush 

首先的Push里简单的 

alert、badge、sound和combined就不过多的介绍了 

就是推送简单的提示和声音,以及组合等推送。 

重点介绍推送有数据内容的部分 

payload有两种方法 

其内部调用的内容不相同 

其中一个是单线程的推送 

通过PushNotificationManager发送推送 

Java代码  -111.png

  1. public static PushedNotifications payload(Payload payload, Object keystore, String password, boolean production, Object devices) throws CommunicationException, KeystoreException {  
  2.         return sendPayload(payload, keystore, password, production, devices);  
  3.     }

  

可以传递要推送设备Token的List,Payload里面就是要推送的方式以及推送的内容字典等。 

另外一个就是多线程的推送 

Java代码  %!(EXTRA markdown.ResourceType=, string=, string=)

  1. public static PushedNotifications payload(Payload payload, Object keystore, String password, boolean production, int numberOfThreads, Object devices) throws Exception {  
  2.         if (numberOfThreads <= 0) return sendPayload(payload, keystore, password, production, devices);  
  3.         AppleNotificationServer server = new AppleNotificationServerBasicImpl(keystore, password, production);  
  4.         List deviceList = Devices.asDevices(devices);  
  5.         NotificationThreads threads = new NotificationThreads(server, payload, deviceList, numberOfThreads);  
  6.         threads.start();  
  7.         try {  
  8.             threads.waitForAllThreads(true);  
  9.         } catch (InterruptedException e) {  
  10.         }  
  11.         return threads.getPushedNotifications(true);  
  12.     }

  

以上方法都是同步执行的,也就是当发送推送之后得到反馈才继续往下执行 

—————- 

下面介绍queue方法 

Java代码  %!(EXTRA markdown.ResourceType=, string=, string=)

  1. public static PushQueue queue(Object keystore, String password, boolean production, int numberOfThreads) throws KeystoreException {  
  2.         AppleNotificationServer server = new AppleNotificationServerBasicImpl(keystore, password, production);  
  3.         PushQueue queue = numberOfThreads <= 1 ? new NotificationThread(server) : new NotificationThreads(server, numberOfThreads);  
  4.         return queue;  
  5.     }

  

这个方法是异步执行,执行完之后,不需要等待推送的反馈即可直接往下执行 

在这你会发现,其实推送用的都是NotificationThread或者NotificationThreads 

而这两个类有若干重载的构造方法 

使用不同的构造方法来决定到底是同步还是异步推送 

接下来是payloads方法 

也是有两个重载的方法 

也分别对应单线程和多线程 

这个方法主要是可以针对不同的设备Token发送不同的信息内容 

也就是说,针对于每一个设备有属于自己的信息内容 

这里面主要使用的就是 PayloadPerDevice这个类 

里面是一对一的内容,一个Payload,对应一个Token 

以上大体就是JavaPNS最简单基础的使用方法,关于Push类的使用

文章目录
  1. 1. JavaPNS初级使用,关于Push工具类的使用
    1. 1.0.1. JavaPNS初级使用,关于Push工具类的使用