23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Such settings, by the way, might include tile, badge, and other notification activities that you might<br />

have established, as those can generate network traffic. If you’re also using background transfers, you<br />

can set the cost policies for downloads and uploads as well.<br />

An app can, of course, ask the user’s permission for any given network operation. It’s up to you and<br />

your designers to decide when to ask and how often. Windows Store policy, for its part (section 4.5),<br />

requires that you ask the user for any transfer exceeding one megabyte when roaming and<br />

overDataLimit are both true, and when performing any transfer over maxTransferSizeInMegabytes.<br />

On a fixed type network, where data is unrestricted up to dataPlanLimitInMegabytes, we find cases<br />

where a number of the other properties become interesting. For example, if overDataLimit is already<br />

true, you can ask the user to confirm additional network traffic or just defer certain operations until the<br />

nextBillingCycle. Or, if approachingDataLimit is true (or even when it’s not), you can determine<br />

whether a given operation might exceed that limit. This is where the connection profile’s getLocalUsage<br />

method comes in handy to obtain a DataUsage object for a given period (see How to retrieve<br />

connection usage information for a specific time period). Call getLocalUsage with the time period<br />

between lastSyncTime and DateTime.now(). Then add that value to megabytesUsed and subtract the<br />

result from dataPlanLimitInMegabytes. This tells you how much more data you can transfer before<br />

incurring extra costs, thereby providing the basis for asking the user, “Downloading this file will exceed<br />

your data plan limit. Do you want to proceed?”<br />

For simplicity’s sake, you can think of cost awareness in terms of three behaviors: normal,<br />

conservative, and opt-in, which are described on Managing connections on metered networks and,<br />

more broadly, on Developing connected apps. Both topics provide additional guidance on making the<br />

kinds of decisions described here already. In the end, saving the user from bill shock—and designing a<br />

great user experience around network costs—is definitely an essential investment.<br />

Sidebar: Simulating Metered Networks<br />

You may be thinking, “OK, so I get the need for my app to behave properly with metered<br />

networks, but how do I test such conditions without signing up with some provider and paying<br />

them a bunch of money (including roaming fees) while I’m doing my testing?” The simple answer<br />

is that you can simulate the behavior of metered networks with any Wi-Fi connection. First, invoke<br />

the Settings charm and tap on your network connection near the bottom (see below left,<br />

specifically the upper left icon, shown here as “Nuthatch”). In the Networks pane that then opens<br />

up (below right), right-click a wireless connection to open the menu and then select Set As<br />

Metered Connection:<br />

638

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!