我目前正在使用 stackmob 为 android 和 iOS 推送通知。我正在使用他们的 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();
}
}