問題:私のコードは正常に実行され、エラーもなく、適切なログ結果も表示されるように見えますが、プッシュ通知が iPhone に届きません。Mac で実行されている Apache Tomcat: Mountain Lion から通知を送信しています。
注: PHP の .pem 形式を除いて、同じ証明書を使用してこれを実行できます。Javapns は .pem を受け入れないので、.p12 ファイルを使用します。私の証明書の .pem バージョンは php で動作するので、この問題全体が javapns の欠点であると疑い始めています。
背景:
以下のコードはエラーなしで実行され、notifications.isSuccessful()
実際には true が返されます。しかし、デバイスにメッセージが表示されず、エラーも発生しません。以前に間違ったキーを使用したときは適切なエラーが発生し、トークン文字列が長すぎるとエラーが発生しました。これで、アプリケーションは最終的に例外なく実行されますが、デバイスには何も到達していません。
String keyFilePath = request.getServletContext().getRealPath("")+System.getProperty("file.separator")+"keys"+System.getProperty("file.separator")+"key.p12";
List<PushedNotification> notifications = Push.combined (pushNotificationMessage, 1, "Sound.wav", keyFilePath, "Password", false, userToken);
for (PushedNotification notification : notifications) {
if (notification.isSuccessful()) {
System.out.println("Push notification sent successfully to: " +
notification.getDevice().getToken());
} else {
String invalidToken = notification.getDevice().getToken();
Exception theProblem = notification.getException();
theProblem.printStackTrace();
/* If the problem was an error-response packet returned by Apple, get it */
ResponsePacket theErrorResponse = notification.getResponse();
if (theErrorResponse != null) {
System.out.println(theErrorResponse.getMessage());
}
}
}
ログ
2014-05-16 20:29:21 DEBUG Payload:219 - Adding alert [blah blah blah]
2014-05-16 20:29:21 DEBUG Payload:193 - Adding badge [1]
2014-05-16 20:29:21 DEBUG Payload:205 - Adding sound [Sound.wav]
2014-05-16 20:29:21 DEBUG ConnectionToAppleServer:94 - Creating SSLSocketFactory
2014-05-16 20:29:21 DEBUG ConnectionToAppleServer:149 - Creating SSLSocket to gateway.sandbox.push.apple.com:2195
2014-05-16 20:29:22 DEBUG PushNotificationManager:111 - Initialized Connection to Host: [gateway.sandbox.push.apple.com] Port: [2195]: 5dec07cc[SSL_NULL_WITH_NULL_NULL: Socket[addr=gateway.sandbox.push.apple.com/17.172.232.45,port=2195,localport=51223]]
2014-05-16 20:29:22 DEBUG PushNotificationManager:538 - Building Raw message from deviceToken and payload
2014-05-16 20:29:22 DEBUG PushNotificationManager:617 - Built raw message ID 1 of total length 154
2014-05-16 20:29:22 DEBUG PushNotificationManager:396 - Attempting to send notification: {"aps":{"sound":"Sound.wav","alert":"blah blah blah","badge":1}}
2014-05-16 20:29:22 DEBUG PushNotificationManager:397 - to device: cb45519c4516907a03b3b5c2f0e48aa51f6f3d900cb7598f4e3c4482b33afea8
2014-05-16 20:29:22 DEBUG PushNotificationManager:415 - Flushing
2014-05-16 20:29:22 DEBUG PushNotificationManager:417 - At this point, the entire 154-bytes message has been streamed out successfully through the SSL connection
2014-05-16 20:29:22 DEBUG PushNotificationManager:420 - Notification sent on first attempt
2014-05-16 20:29:22 DEBUG PushNotificationManager:222 - Reading responses
2014-05-16 20:29:27 DEBUG PushNotificationManager:200 - Closing connection
Push notification sent successfully to: cb45519c4516907a03b3b5c2f0e48aa51f6f3d900cb7598f4e3c4482b33afea
登録
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIRemoteNotificationType notificationTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (notificationTypes != (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound) ) {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound) ];
NSLog(@"Reregistering for notifications");
} else {
NSLog(@"Notifications Found");
}
return YES
}
トークンの取得
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *stringToken = [[[[deviceToken description]
stringByReplacingOccurrencesOfString: @"<" withString: @""]
stringByReplacingOccurrencesOfString: @">" withString: @""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
//[NSString stringWithFormat:@"%@",deviceToken];
[self sendPNToken:[NSString stringWithFormat:@"%@",stringToken]];
NSLog(@"StringToken: %@",stringToken);
}
システム
マウンテン ライオン/Mac、Apache Tomcat、JDK 1.7