diff --git a/README.md b/README.md index 1047cb48..0e77e014 100644 --- a/README.md +++ b/README.md @@ -304,15 +304,30 @@ ### Custom Client 样例 -> 一下片断来自项目代码里面的文件:example / cn.jpush.api.examples.DeviceExample +> 一下片断来自项目代码里面的文件:example / cn.jpush.api.examples.ClientExample ```Java public static void testCustomClient() { ClientConfig config = ClientConfig.getInstance(); - config.setMaxRetryTimes(5); - config.setConnectionTimeout(10 * 1000);// 10 seconds - config.setSSLVersion("TLSv1.1"); - ClientConfig.setReadTimeout(ClientConfig.getInstance(), 30 * 1000);// 30 seconds - JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config); + config.setMaxRetryTimes(5); + config.setConnectionTimeout(10 * 1000); // 10 seconds + config.setSSLVersion("TLSv1.1"); // JPush server supports SSLv3, TLSv1, TLSv1.1, TLSv1.2 + + ClientConfig.setReadTimeout(ClientConfig.getInstance(), 30 * 1000); // 30 seconds + + JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config); } + + public static void testCustomPushClient() { + ClientConfig config = ClientConfig.getInstance(); + config.setApnsProduction(false); // development env + config.setTimeToLive(60 * 60 * 24); // one day + + // config.setGlobalPushSetting(false, 60 * 60 * 24); // development env, one day + + JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config); // JPush client + + // PushClient pushClient = new PushClient(masterSecret, appKey, null, config); // push client only + + } ``` diff --git a/example/main/java/cn/jpush/api/examples/ClientExample.java b/example/main/java/cn/jpush/api/examples/ClientExample.java new file mode 100644 index 00000000..2b65fb8e --- /dev/null +++ b/example/main/java/cn/jpush/api/examples/ClientExample.java @@ -0,0 +1,59 @@ +package cn.jpush.api.examples; + +import cn.jpush.api.JPushClient; +import cn.jpush.api.common.ClientConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ClientExample { + protected static final Logger LOG = LoggerFactory.getLogger(ClientExample.class); + + private static final String appKey = "dd1066407b044738b6479275"; + private static final String masterSecret = "6b135be0037a5c1e693c3dfa"; + private static final String TAG1 = "tag1"; + private static final String ALIAS1 = "alias1"; + private static final String ALIAS2 = "alias2"; + private static final String REGISTRATION_ID1 = "0900e8d85ef"; + private static final String REGISTRATION_ID2 = "0a04ad7d8b4"; + + + public static void main(String[] args) { +// testDefaultClient(); +// testCustomClient(); + testCustomPushClient(); + } + + public static void testDefaultClient() { + JPushClient client = new JPushClient(masterSecret, appKey); + + // JPushClient client1 = new JPushClient(masterSecret, appKey, null, ClientConfig.getInstance()); + } + + public static void testCustomClient() { + ClientConfig config = ClientConfig.getInstance(); + config.setMaxRetryTimes(5); + config.setConnectionTimeout(10 * 1000); // 10 seconds + config.setSSLVersion("TLSv1.1"); // JPush server supports SSLv3, TLSv1, TLSv1.1, TLSv1.2 + + ClientConfig.setReadTimeout(ClientConfig.getInstance(), 30 * 1000); // 30 seconds + + JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config); + } + + public static void testCustomPushClient() { + ClientConfig config = ClientConfig.getInstance(); + + config.setApnsProduction(false); // development env + config.setTimeToLive(60 * 60 * 24); // one day + + // config.setGlobalPushSetting(false, 60 * 60 * 24); // development env, one day + + JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config); // JPush client + + // PushClient pushClient = new PushClient(masterSecret, appKey, null, config); // push client only + + } + +} + + diff --git a/example/main/java/cn/jpush/api/examples/DeviceExample.java b/example/main/java/cn/jpush/api/examples/DeviceExample.java index ba0b64e5..76645e57 100644 --- a/example/main/java/cn/jpush/api/examples/DeviceExample.java +++ b/example/main/java/cn/jpush/api/examples/DeviceExample.java @@ -1,7 +1,6 @@ package cn.jpush.api.examples; import cn.jpush.api.JPushClient; -import cn.jpush.api.common.ClientConfig; import cn.jpush.api.common.resp.APIConnectionException; import cn.jpush.api.common.resp.APIRequestException; import cn.jpush.api.common.resp.DefaultResult; @@ -28,7 +27,6 @@ public class DeviceExample { public static void main(String[] args) { // testGetDeviceTagAlias(); // testGetUserOnlineStatus(); - testCustomClient(); } public static void testGetDeviceTagAlias() { @@ -78,17 +76,6 @@ public static void testBindMobile() { LOG.info("Error Message: " + e.getErrorMessage()); } } - - public static void testCustomClient() { - ClientConfig config = ClientConfig.getInstance(); - config.setMaxRetryTimes(5); - config.setConnectionTimeout(10 * 1000);// 10 seconds - config.setSSLVersion("TLSv1.1"); - - ClientConfig.setReadTimeout(ClientConfig.getInstance(), 30 * 1000);// 30 seconds - - JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config); - } } diff --git a/src/main/java/cn/jpush/api/JPushClient.java b/src/main/java/cn/jpush/api/JPushClient.java index 0974e573..425381f7 100644 --- a/src/main/java/cn/jpush/api/JPushClient.java +++ b/src/main/java/cn/jpush/api/JPushClient.java @@ -124,7 +124,7 @@ public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpPr * * If you are using JPush privacy cloud, and you want different settings from default globally, * maybe this constructor is what you needed. - * This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setGolbalPushSetting} instead of this constructor. + * This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setGlobalPushSetting} instead of this constructor. * * @param masterSecret API access secret of the appKey. * @param appKey The KEY of one application on JPush. @@ -151,7 +151,7 @@ public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpPr * * If you are using JPush privacy cloud, and you want different settings from default globally, * maybe this constructor is what you needed. - * This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setGolbalPushSetting} instead of this constructor. + * This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setGlobalPushSetting} instead of this constructor. * * @param masterSecret API access secret of the appKey. * @param appKey The KEY of one application on JPush. @@ -174,7 +174,7 @@ public JPushClient(String masterSecret, String appKey, HttpProxy proxy, ClientCo * Create a JPush Client with global settings. * * If you want different settings from default globally, this constructor is what you needed. - * This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setGolbalPushSetting} instead of this constructor. + * This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setGlobalPushSetting} instead of this constructor. * * @param masterSecret API access secret of the appKey. * @param appKey The KEY of one application on JPush. diff --git a/src/main/java/cn/jpush/api/common/ClientConfig.java b/src/main/java/cn/jpush/api/common/ClientConfig.java index 76517e45..9cde3d1d 100644 --- a/src/main/java/cn/jpush/api/common/ClientConfig.java +++ b/src/main/java/cn/jpush/api/common/ClientConfig.java @@ -229,7 +229,7 @@ public void setTimeToLive(long timeToLive) { setTimeToLive(this, timeToLive); } - public void setGolbalPushSetting(boolean apnsProduction, long timeToLive) { + public void setGlobalPushSetting(boolean apnsProduction, long timeToLive) { setApnsProduction(this, apnsProduction); setTimeToLive(timeToLive); } diff --git a/src/main/java/cn/jpush/api/push/PushClient.java b/src/main/java/cn/jpush/api/push/PushClient.java index 496b0ca1..835aea67 100644 --- a/src/main/java/cn/jpush/api/push/PushClient.java +++ b/src/main/java/cn/jpush/api/push/PushClient.java @@ -121,7 +121,7 @@ public PushClient(String masterSecret, String appKey, boolean apnsProduction, lo } /** - * This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setGolbalPushSetting} instead of this method. + * This will be removed in the future. Please use ClientConfig{@link cn.jpush.api.common.ClientConfig#setGlobalPushSetting} instead of this method. * * @param apnsProduction Global APNs environment setting. It will override PushPayload Options. * @param timeToLive Global time_to_live setting. It will override PushPayload Options.