×
Namespaces

Variants
Actions

检测推送通知是否会因为节电模式而被禁用

From Nokia Developer Wiki
Jump to: navigation, search

在Windows Phone8.1中,“设置”->“节电模式”中的设置有可能阻止程序的推送通知,会影响一些对推送有很高要求的产品的用户体验。这篇文章主要介绍如何在Windows Phone8.1中检测节电模式是否开启,从而应用程序可以友好的提示用户注意推送通知设置。

WP Metro Icon WP8.png
Article Metadata

测试基于
SDK: Windows Phone 8.0 SDK

兼容于
文章
段博琼 在 26 May 2014 创建
最后由 Cxt_programmer 在 27 May 2014 编辑

Contents

概述

在 Windows Phone8.1 的设置里面,微软去掉了"后台" 设置选项,而是集成到了节电模式设置里面, 当手机启用 "节电模式"时,如果接收到不到推送通知,可能是因为用户没有开启应用在节电模式下,允许 后台任务。

步骤

以微信为例,在 Windows Phone 8.1的手机上,点击"设置" -> "节电模式" -> 在”使用量" 中 选择微信 -> 选择 "即使节电模式已打开,也运行此应用在后台运行" :

1)选择节电模式:
选择节电模式



2)选择"微信":
选择"微信"

3)允许在节电模式时运行后台:
允许在节电模式时运行后台

4)此时,在节电模式时,也能接收到推送,否则,无推送:
在节电模式时,也能接收到推送

检测手机节电模式变化,并提示用户

在应用运行时,可以选择判断当前用户的手机是否已经开启了节电模式,如果 已经开启了,可以提示用户,在设置中开启“即使节电模式已经打开,也允许 此应用在后台运行”。

代码:

 public void CheckBatterySaverState()
{
// 支持 PowerSavingModeEnabled 属性的最低操作系统属性
Version TargetVersion = new Version(8, 0, 10492);
 
Windows.Phone.System.Power.PowerManager.PowerSavingModeChanged += PowerManager_PowerSavingModeChanged;
if (Environment.OSVersion.Version >= TargetVersion)
{
// 使用反射获取 PowerSavingModeEnabled 值
bool powerSaveOn = (bool)
typeof(Windows.Phone.System.Power.PowerManager).GetProperty("PowerSavingModeEnabled").GetValue(null, null);
 
if (powerSaveOn)
{
MessageBox.Show("节电模式已经打开,请在设置中,允许此应用在后台运行以正常接收推送通知");
}
else
{
MessageBox.Show("节电模式已经关闭");
}
}
}
 
void PowerManager_PowerSavingModeChanged(object sender, object e)
{
MessageBox.Show("节电模式已改变:" + Windows.Phone.System.Power.PowerManager.PowerSavingMode);
}

Version Hint

Windows Phone: [[Category:Windows Phone]]
[[Category:Windows Phone 7.5]]
[[Category:Windows Phone 8]]

Nokia Asha: [[Category:Nokia Asha]]
[[Category:Nokia Asha Platform 1.0]]

Series 40: [[Category:Series 40]]
[[Category:Series 40 1st Edition]] [[Category:Series 40 2nd Edition]]
[[Category:Series 40 3rd Edition (initial release)]] [[Category:Series 40 3rd Edition FP1]] [[Category:Series 40 3rd Edition FP2]]
[[Category:Series 40 5th Edition (initial release)]] [[Category:Series 40 5th Edition FP1]]
[[Category:Series 40 6th Edition (initial release)]] [[Category:Series 40 6th Edition FP1]] [[Category:Series 40 Developer Platform 1.0]] [[Category:Series 40 Developer Platform 1.1]] [[Category:Series 40 Developer Platform 2.0]]

Symbian: [[Category:Symbian]]
[[Category:S60 1st Edition]] [[Category:S60 2nd Edition (initial release)]] [[Category:S60 2nd Edition FP1]] [[Category:S60 2nd Edition FP2]] [[Category:S60 2nd Edition FP3]]
[[Category:S60 3rd Edition (initial release)]] [[Category:S60 3rd Edition FP1]] [[Category:S60 3rd Edition FP2]]
[[Category:S60 5th Edition]]
[[Category:Symbian^3]] [[Category:Symbian Anna]] [[Category:Nokia Belle]]

  - 设置您的应用以接收 Windows Phone 的推送通知: http://msdn.microsoft.com/zh-cn/library/windowsphone/develop/hh202940(v=vs.105).aspx
This page was last modified on 27 May 2014, at 06:45.
129 page views in the last 30 days.
×