[Cover] [Previous Section] [Next Section] [Index]
Current chapter: Creating HDML Services that "Push" Information
Section 40 out of 67 total sections
, Section 9 out of 11 sections in this chapter
Combining alerts and HDML content in pull notifications
The advantage of using a pull notification that contains both an alert and HDML content is that it gives the user a sense of extremely responsive performance. Because the information you provide is preloaded into the phone, the phone displays it immediately when the user selects the alert; there is no need for an additional network exchange. There are, however, several possible disadvantages with this approach:
- If the UP.Phone is on a circuit-switched network, the UP.Link server won't deliver the notification until the subscriber turns the UP.Phone on and establishes a circuit.
- The information that the phone preloads and caches might become obsolete by the time the user selects the alert.
For this reason, it is recommended that you use push notifications for highly volatile information such as stock quotes.
Suppose you want to implement the notification that informs the user of the timely sports headline shown in Figure 5-9.
FIGURE 5-9.
Pull notification containing an alert and HDML content
To create this interface, you use two components (or applications):
- An application that sends a pull notification to the UP.Phone. The pull specifies the URL of a digest which the UP.Phone preloads.
- An application that provides the digest specified by the pull notification. The digest includes a single HDML deck, which provides the content, and an alert.
The following sections provide example code that implements these two applications.
The pull notification application
The following code sends the pull notification (shown in Figure 5-9) to subscriber 859852091-411_updev.uplanet.com:
#include <stdio.h>
#include <stdlib.h>
/* In sdk_installdir/include/uplapi/ */
#include "ntfnscc.h"
#include "ntfnclnt.h"
int main()
{
int httpStatus;
char subId[256] = "859852091-411_updev.uplanet.com";
/* Code that provides this digest is provided below. */
char url[256] = "http://www.foo.com/digests/headline.cgi";
/* Create non-secure client. */
TNtfnClient *client = new TNtfnClient("updev.uplanet.com");
httpStatus = client->PostPrefetch(subId, url, 0);
if (httpStatus != CHTTPStatusNoContent)
{
printf("Notification failed with HTTP status: %d\n",
httpStatus);
}
}
Application that provides the digest (HDML deck and alert)
The following program provides the digest specified by the pull notification in the previous section. It includes the alert and the deck shown in Figure 5-9).
/*
** Implements: http://www.foo.com/digests/headline.cgi
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "digest.h" /* In install_dir/examples/source/digests
*/
int main ()
{
Digest d;
char *output;
char alertType[5] = "D---";
char alertTitle[256] = "Cubs, Sox in World Series!";
/* Create the Digest object */
d = DigestConstruct();
/* Add a deck and an alert to the digest. */
DigestAddDeck(d, "?", "<HDML VERSION=3.0><DISPLAY> "
"<ACTION TYPE=ACCEPT TASK=GO DEST=?NS=DECK2>"
"The Cubs will face the White Sox in the World" Series"
"after the Sox surprise victory over the Yankees."
"</DISPLAY></HDML>");
DigestAddAlert(d, alertType, "?", alertTitle);
/* Create MIME multipart message to send as HTTP response
*/
output = DigestSerialize(d);
printf("%s",output);
/* Free the output buffer and destroy the Digest obj. */
free(output);
DigestDestruct(d);
}
[Cover] [Previous Section] [Next Section] [Index]
Current chapter: Creating HDML Services that "Push" Information
Section 40 out of 67 total sections
, Section 9 out of 11 sections in this chapter
Copyright © 1999, Unwired Planet, Inc. All rights
reserved.