Use a background agent to keep membership information and deals associated with your app up-to-date. You can create a Wallet agent for membership and deals in the same manner as shown earlier in this chapter.
The sample app includes a declaration of the deals background agent in the WMAppManifest.xml file, shown in the following excerpt:
<Tasks>
...
<ExtendedTask Name="BackgroundTask">
<BackgroundServiceAgent
Specifier="WalletAgent"
Name="DealsAndMembershipAgent"
Source="DanielVaughan.WPUnleashed.MembershipAgent"
Type="DanielVaughan.WPUnleashed.DealsAndMembershipAgent" />
</ExtendedTask>
</Tasks>
The sample’s DealsAndMembershipAgent
updates the Unleashed Membership card (see Listing 25.14). It also retrieves a random coupon to display in the Wallet. The WalletTransactionItem
object’s MessageNavigationUri
property provides a deep link back to the CouponView
from the Wallet (see Listing 25.14.).
protected override async void OnRefreshData(RefreshDataEventArgs args)
{
var service = (IDealsAndMembershipService)new DealsAndMembershipServiceClient();
foreach (WalletTransactionItem card in args.Items.OfType< WalletTransactionItem>())
{
try
{
int balanceRemaining = await Task<int>.Factory.FromAsync(
service.BeginGetAvailableBalance,
service.EndGetAvailableBalance, null);
card.DisplayAvailableBalance = balanceRemaining + " points";
Coupon coupon = await Task<Coupon>.Factory.FromAsync(
service.BeginGetRandomCoupon,
service.EndGetRandomCoupon, null);
card.Message = "You might be interested in " + coupon.Description;
card.MessageNavigationUri
= new Uri("/CouponView/CouponView.xaml?CouponId="
+ coupon.Id, UriKind.Relative);
await card.SaveAsync();
}
catch (Exception ex)
{
Debug.Assert(false, "An error occurred during updating of a card. " + ex);
continue;
}
}
NotifyComplete();
}
The Open App link, on the deal’s About page, navigates back to the sample app’s CouponView page (see Figure 25.7). The available balance and the random deal is updated whenever the user taps the Refresh menu item in the application bar.
More and more businesses are using coupons to attract trade. Now Windows Phone has established coupons and deals as a core experience on the phone. Integrating Wallet capabilities for loyalty cards and deals offers you as a developer a great way to enrich your app.
18.226.104.177