これは私の以前のStackOverflowのpostingのフォローアップです。JavaとRESTを使用してApple Push Notificationを送信する際の問題
以前のスレッドに新しい質問を追加するのではなく、新しい投稿を開始するのが良い(以前よりも進歩して以来)。
ここ
は私が完了している段階です... RESTベースのWebサービスを介して、アップルのプッシュ通知を送信するためにはGoogle Code上Javapnsライブラリを使用しています:
iPhoneデベロッパプログラムのポータル( IDPP):
(1)アプリケーションIDとAPNSベースのSSL証明書とキーを作成しました。
(2)プロビジョニングプロファイルを作成してインストールしました。
(3)サーバーにSSL証明書とキーをインストールしました。
(4)私のiPhoneアプリを設定して、リモート通知を登録します。
XCodeの:
は、私が建てたときに私のデバイストークンを取得することができましたし、私のデバイス上に私のアプリを導入しました。
私のiPhoneアプリがデプロイされるとすぐに、私のアプリがプッシュ通知を送信したいというダイアログが私のiPhoneに表示され、許可するように頼まれました。
Log4Jステートメントを使用してWebサービスを呼び出すと、RESTベースのWebサービスが実際に呼び出されたことがわかりましたが、私のiPhoneアプリでプッシュ通知を受け取ったことはありませんでした。
ApnsManagerクラス:
public class ApnsManager {
/** APNs Server Host **/
private static final String HOST = "gateway.sandbox.push.apple.com";
/** APNs Port */
private static final int PORT = 2195;
public void sendNotification(String deviceToken)
throws Exception {
try {
PayLoad payLoad = new PayLoad();
payLoad.addAlert("My alert message");
payLoad.addBadge(45);
payLoad.addSound("default");
PushNotificationManager pushManager =
PushNotificationManager.getInstance();
pushManager.addDevice("iPhone", deviceToken);
log.warn("Initializing connectiong with APNS...");
// Connect to APNs
pushManager.initializeConnection(HOST, PORT,
"/etc/Certificates.p12", "password",
SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);
Device client = pushManager.getDevice("iPhone");
// Send Push
log.warn("Sending push notification...");
pushManager.sendNotification(client, payLoad);
pushManager.stopConnection();
}
catch (Exception e) {
e.printStackTrace("Unable to send push ");
}
}
}
RESTfulなWebサービス:
@Path(ApnService.URL)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public class ApnService {
public static final String URL = "/apns";
@GET
@Path("send")
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public String send() throws JSONException, IOException {
String msg = "";
try {
log.debug("Inside ApnService.send() method.");
log.debug("Sending notification to device");
ApnManager.sendNotification("32b3bf28520b977ab8eec50b482
25e14d07cd78 adb69949379609e40401d2d1de00000000738518e5c
000000003850978c38509778000000000000000000398fe12800398f
e2e0398fe1040000");
} catch(Exception e) {
e.printStackTrace();
msg = "fail";
}
msg = "success";
StringWriter sw = new StringWriter();
JsonFactory f = new JsonFactory();
JsonGenerator g = f.createJsonGenerator(sw);
g.writeStartObject();
g.writeStringField("status", msg);
g.writeEndObject();
g.close();
return sw.toString();
}
}
今、私は私のアプリサーバに私のアプリを展開し、残りのクライアントを開き、入力したときに:
http:// localhost:8080/myapp/apns/send
残りのクライアントは、これを返します。
HTTP/1.1 200 OK
次のログメッセージが私のコンソールに出力されます。
01:47:51,985 WARN [ApnsManager] Initializing connectiong with APNS...
01:47:52,318 WARN [ApnsManager] Sending push notification...
MyAppDelegate.m
- (void) applicationDidFinishLaunching :
(UIApplication*) application
{
NSLog(@"LAUNCH");
// Configure REST engine
RESTAPI* api = [RESTAPI getInstance];
[api setNetworkAddress:kLocalAddress port:kDefaultPort];
UIRemoteNotificationType notificationTypes
= UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound;
if ([[UIApplication sharedApplication] enabledRemoteNotificationTypes]
!= notificationTypes) {
NSLog(@"Registering for remote notifications...");
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:notificationTypes];
} else {
NSLog(@"Already registered for remote notifications...");
// Uncomment this if you want to unregister
// NSLog(@"Unregistering for remote notifications...");
// [[UIApplication sharedApplication] unregisterForRemoteNotifications];
}
mainWindow = [[[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds] retain];
toolsNav = [[[ToolsNav alloc] init] retain];
[mainWindow addSubview:toolsNav.view];
[mainWindow makeKeyAndVisible];
}
しかし、私のアプリ(私のiPhoneにある)にプッシュ通知はありません!私はおそらく間違って何をしていることができ
本当にこの時点で困惑
アム...? :(
は、それが(すみません、私はRESTに初心者です)、私は私のRESTfulなWebサービスをセットアップする方法に問題ですか?誰かがこれで私を助けることができれば
はそれを本当に感謝だろう...
間違ったトークンを印刷しました!生成したデバイストークン文字列が長すぎるように見えた
トークン文字列にはスペースが含まれています。ここにコードをコピーしたときに導入されましたか?削除してください。 – notnoop
Hi Saeed ...はい、トークン文字列のスペースは、コードをコピーしたときに導入されました(そして、ここでより視覚的にするためにコードを再フォーマットしました)。私の実際のコードにはスペースはありません。私はまだ立ち往生していますので、誰かが私にこれを手伝ってもらえると感謝します。私は少しスニッチを実行していると私はポート2195に接続したいと私に尋ねるWebサービスを実行すると、それはプッシュ通知を送信します。 iPhoneのアプリには表示されません。私が間違っていることはありますか? RESTコードですか? –
実装したUIApplicationDelegateの「リモート通知の処理」メソッドのコードも含める必要があります。 – bpapa