1
我目前使用stackmob進行android和iOS的推送通知。 我正在使用他們的Java客戶端發送推送通知。StackMob Java客戶端
我給了正確的API_KEY和API_SECRET。 deviceToken也是正確的,但它有時會給我一個401錯誤,有時會有一個200狀態碼,但我無法接收任何推送通知。 這是我的示例代碼。
公共類TestSample {
public static String API_KEY = "Some key";
public static String API_SECRET = "Some key";
public static String USER_OBJECT_NAME = "user";
public static int API_VERSION = 0;
public static void main(String[] args) {
new TestSample();
}
public TestSample()
{
String deviceToken="Token";
init();
StackMob stackmob=getStackMobInstance();
stackmob.registerForPushWithUser("rathi", deviceToken, new StackMobRawCallback() {
@Override
public void done(HttpVerb arg0, String arg1,
List<Entry<String, String>> arg2, String arg3, Integer arg4,
List<Entry<String, String>> arg5, byte[] arg6) {
System.out.println("HEree1");
}
});
StackMobPushToken x=new StackMobPushToken(registrationID, TokenType.iOS);
final Map<String, String> payload = new HashMap<String, String>();
ArrayList<StackMobPushToken>tokens=new ArrayList<StackMobPushToken>();
tokens.add(x);
payload.put("badge", "1");
payload.put("sound", "customsound.wav");
payload.put("alert", "Hello from Stackmob!");
payload.put("other", "stuff");
stackmob.pushToTokens(payload, tokens, new StackMobRawCallback() {
@Override
public void done(HttpVerb arg0, String arg1,
List<Entry<String, String>> arg2, String arg3, Integer arg4,
List<Entry<String, String>> arg5, byte[] arg6) {
System.out.println("HEree");
}
});
}
public void init() {
StackMob.setStackMob(new StackMob(API_KEY, API_SECRET, USER_OBJECT_NAME, API_VERSION));
//StackMob.getStackMob().setSession(new StackMobAndroidSession(c, StackMob.getStackMob().getSession()));
StackMob.getStackMob().setSession(new StackMobSession(StackMob.getStackMob().getSession()));
StackMob.setUserAgentName("iOS");
StackMob.setLogger(new StackMobLogger());
StackMob.getLogger().setLogging(true);
StackMobRequest.setCookieStore(new StackMobCookieStore());
}
public static StackMob getStackMobInstance() {
return StackMob.getStackMob();
}
}