Ionic 离子电容器|系统通知访问请求(通知或任何其他)

am46iovg  于 2023-03-16  发布在  Ionic
关注(0)|答案(1)|浏览(136)

如何弹出系统“请求通知访问”窗口的Android与离子电容器?

PushNotifications.requestPermissions()的文档称**“android always receive notification”(安卓始终接收通知),这是错误的**。某些品牌(如三星)或用户可以默认禁用它们。

**
 * Request permission to receive push notifications.
 *
 * On Android it doesn't prompt for permission because you can always
 * receive push notifications.
 *
 * On iOS, the first time you use the function, it will prompt the user
 * for push notification permission and return granted or denied based
 * on the user selection. On following calls it will get the current status of
 * the permission without prompting again.
 *
 * @since 1.0.0
 */
requestPermissions(): Promise<PermissionStatus>;

还将此添加到AndroidManifest.xml,但没有任何内容。

<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
2j4z5cfb

2j4z5cfb1#

文档显示和示例:

const registerNotifications = async () => {
 let permStatus = await PushNotifications.checkPermissions();

 if (permStatus.receive === 'prompt') {
  permStatus = await PushNotifications.requestPermissions();
 }

 if (permStatus.receive !== 'granted') {
  throw new Error('User denied permissions!');
 }

 await PushNotifications.register();
}

https://capacitorjs.com/docs/apis/push-notifications

相关问题