JAVA APNS 기반 ios 푸 시 실현

2397 단어
maven 좌표
        
            com.github.fernandospr
            javapns-jdk16
            2.4.0
        

코드
import javapns.Push;
import javapns.devices.Device;
import javapns.devices.implementations.basic.BasicDevice;
import javapns.notification.*;
import lombok.extern.slf4j.Slf4j;

import java.util.*;

/**
 * @ClassName: IosPush
 * @Author:   
 * @Date: 2019/7/31 17:09
 * @Description :
 */
@Slf4j
public class IosPush2 {
    public static void main(String[] args) throws Exception {
        
        //war      
        //String keystore = Thread.currentThread().getContextClassLoader().getResources("fileName").getPath();
        String keystore = "";//  ,p12  
        String password = "";//    
        String deviceToken = ""; //  token,     
        PushNotificationPayload payload = new PushNotificationPayload();
        payload.addBadge(1);//        
       // payload.addAlert("alert");
        payload.addCustomAlertBody("fuck me");//       
        //   k,v
        ///payload.addCustomDictionary("key","val");
        //payload.addCustomDictionary("key2","val2");
        payload.addSound("default");//  
        //      
        //PushedNotifications result = Push.payload(payload, keystore, password, false, devicesToken);

        List devices = new LinkedList<>();
        devices.add(deviceToken);
        //                  false        
        PushedNotifications result = Push.payload(payload, keystore, password, false , 1, devices);
        //jar    ,      ,filePath,byte[],InputStream
       // PushedNotifications result = Push.payload(payload, resource.getInputStream(), password, false , 2, iosTokens);
        //    
        PushedNotifications failedNotifications = result.getFailedNotifications();
        System.out.println("    :"+failedNotifications.size());
        failedNotifications.stream().map(fail->fail.getDevice()).collect(Collectors.toList()).forEach(token-> log.info("  token:"+token));
        //    
        PushedNotifications successfulNotifications = result.getSuccessfulNotifications();
        System.out.println("    :"+successfulNotifications.size());
}

좋은 웹페이지 즐겨찾기