Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
```
59 changes: 59 additions & 0 deletions example/main/java/cn/jpush/api/examples/ClientExample.java
Original file line number Diff line number Diff line change
@@ -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

}

}


13 changes: 0 additions & 13 deletions example/main/java/cn/jpush/api/examples/DeviceExample.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -28,7 +27,6 @@ public class DeviceExample {
public static void main(String[] args) {
// testGetDeviceTagAlias();
// testGetUserOnlineStatus();
testCustomClient();
}

public static void testGetDeviceTagAlias() {
Expand Down Expand Up @@ -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);
}

}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/cn/jpush/api/JPushClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/jpush/api/common/ClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/jpush/api/push/PushClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down