ページ

2011-01-04

Phone 7 の Notification で遊ぶ

例によって随分と更新サボっていました。
年末から狩りに行ったり、戦場で狩られたりと遊んでいて何のために Phone 7 買ったのかよくわかりませんね。

さて Phone 7 の Push Notification で遊ぼうと思ってプログラム書きかけていたのですが、実行するとステータスコード 200 が返ってくるのに何の通知も届いていませんでした。

いい加減何とかしないとなぁ...と思ってレスポンスを眺めてみると何やら X-NotificationStatus に怪しげな値がセットされています。

X-DeviceConnectionStatus: Connected
X-NotificationStatus: Suppressed
X-SubscriptionStatus: Active

ドキュメントによると上記のようなレスポンスの場合の説明は次の通り。

The push notification was received and dropped by the Push Notification Service. The Suppressed status can occur if the notification channel was configured to suppress push notifications for a particular push notification class.

HttpNotificationChannel ってチャンネル名以外に何か指定することあるの?と思ってしばらく悩んでいたのですが、何気なく別のページを眺めているうちに解決。
Notification の種類によって X-NotificationClass の値も変わってたんですね。

sendNotificationRequest.ContentType = "text/xml";
sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "token");
sendNotificationRequest.Headers.Add("X-NotificationClass", "");

// Possible batching interval values:
// 1: The message is delivered by the Push Notification Service immediately.
// 11: The message is delivered by the Push Notification Service within 450 seconds.
// 21: The message is delivered by the Push Notification Service within 900 seconds.

Tile Notification の場合 1,11,21 を指定すべきなのに最初に見たサンプルのコピペで 2 を指定していました。
正しい値を指定する事でレスポンスも正常に。

X-DeviceConnectionStatus: Connected
X-NotificationStatus: Received
X-SubscriptionStatus: Active

エミュレータだと何も起こりませんでしたが、実機だとタイルに通知(件数)を表示する事ができました。(その後実行してみるとエミュレータでもちゃんと表示できました)

こうして ようやくタイルに件数を表示できたのですが、今度は表示された件数を消す方法が見あたりません。
いろいろ検索してみると、どうやら消したいときはサーバから再度消すための通知を送らないといけないとか?

http://social.msdn.microsoft.com/Forums/en-US/windowsphone7series/thread/da4b83ec-8e75-4945-b6a7-d914579b41e8/

When the app starts, you will be retrieving the push notification URI, so you can immediately send a new push notification with a zero count and the image you want it to go back to.

該当スレで質問者も言っていますがマジですか? 通知を受けた後、オフラインでプログラム起動したときはどうしたらいいんでしょうね?

0 件のコメント: