notificationManager.requestEnableNotification 卸载以后也不弹窗 - HarmonyOS 鸿蒙Next
notificationManager.requestEnableNotification 卸载以后也不弹窗 - HarmonyOS 鸿蒙Next 使用https://gitee.com/harmonyos_samples/push-kit-sample-code-clientdemo-arkts
这个推送 demo
notificationManager.requestEnableNotification
其中MainAbility
的requestEnableNotification()
报错
[napi_enable_notification.cpp(operator():323)]error, code is 67108902.
Failed to request enable notification: 1600013 Dialog is popping
并且一直不见弹窗
但是今天总体运行的时候,偶尔成功出现弹窗选择是否允许通知。之后再也没出现过
更多关于notificationManager.requestEnableNotification 卸载以后也不弹窗 - HarmonyOS 鸿蒙Next的实战教程也可以访问 https://www.itying.com/category-93-b0.html
您上面的报错信息是由于窗口未初始化完成,我这边运行demo的时候没有复现,如果您这边担心有这种概率事件发生的话,可把权限请求放在首页
aboutToAppear(): void {
Logger.info('MainPage aboutToAppear');
this.handleWant();
this.requestEnableNotification()
}
private requestEnableNotification() {
try {
notificationManager.requestEnableNotification();
Logger.info('Succeeded in requesting enable notification');
} catch (e) {
const err: BusinessError = e;
Logger.error('Failed to request enable notification: %{public}d %{public}s', err.code, err.message);
}
}
更多关于notificationManager.requestEnableNotification 卸载以后也不弹窗 - HarmonyOS 鸿蒙Next的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
在HarmonyOS中,notificationManager.requestEnableNotification
方法用于请求用户启用通知权限。如果应用在卸载后不再弹窗,可能是由于以下原因:
-
权限持久化:HarmonyOS可能会在应用卸载后清除与该应用相关的所有权限设置,包括通知权限。因此,即使之前用户已经启用了通知权限,卸载后重新安装时,权限设置会被重置。
-
系统缓存:系统可能会缓存某些权限状态,但在应用卸载后,这些缓存可能会被清除,导致重新安装时不再弹窗。
-
应用状态:如果应用在卸载时没有正确保存用户的选择或状态,重新安装后系统可能无法识别之前的状态,从而导致不再弹窗。
-
系统策略:HarmonyOS可能会有特定的系统策略,防止应用在卸载后保留某些权限状态,以确保用户隐私和安全。
这些问题可能与HarmonyOS的通知权限管理机制有关,具体行为可能因系统版本或设备不同而有所差异。