美文网首页
h5+plus 手动打开通知

h5+plus 手动打开通知

作者: drneilc | 来源:发表于2022-01-17 11:43 被阅读0次

一、苹果

var app = UIApplication.sharedApplication();
var enabledTypes = 0;
if (app.currentUserNotificationSettings) {
var settings = app.currentUserNotificationSettings();
enabledTypes = settings.plusGetAttribute("types");
} else {
//针对低版本ios系统
enabledTypes = app.enabledRemoteNotificationTypes();
}

console.log("enabledTypes:"+enabledTypes);
if ( 0 == enabledTypes ) {
console.log("在通知栏中开启消息提示");
}else{
console.log("已开启");
}

plus.ios.deleteObject(app);

也可以这样写:

var app = UIApplication.sharedApplication();
var enabledTypes = 0;
if (app.currentUserNotificationSettings) {
var settings = app.currentUserNotificationSettings();
enabledTypes = settings.plusGetAttribute("types");
} else {
//针对低版本ios系统
enabledTypes = app.enabledRemoteNotificationTypes();
}
plus.ios.deleteObject(app);
if ( 0 == enabledTypes ) {
uni.showModal({
title: '提示',
content: '请先打开APP通知权限',
showCancel: false,
success: function (res) {
if (res.confirm) {
var UIApplication = plus.ios.import("UIApplication");
var NSURL = plus.ios.import("NSURL");
var setting = NSURL.URLWithString("app-settings:");
var application = UIApplication.sharedApplication();
application.openURL(setting);
plus.ios.deleteObject(setting);
plus.ios.deleteObject(application);
}
}
});
}

官方示例:

var app = UIApplication.sharedApplication();
var enabledTypes = 0;
if (app.currentUserNotificationSettings) {
var settings = app.currentUserNotificationSettings();
enabledTypes = settings.plusGetAttribute("types");
} else {
enabledTypes = app.enabledRemoteNotificationTypes();
}
plus.ios.deleteObject(app);

二、安卓代码

var pkName = main.getPackageName();
var NotificationManagerCompat = plus.android.importClass("android.support.v4.app.NotificationManagerCompat");
var packageNames = NotificationManagerCompat.from(main);
console.log(JSON.stringify(packageNames));
if (packageNames.areNotificationsEnabled()) {
console.log('已开启通知权限');
}else{
uni.showModal({
title: '提示',
content: '请先打开APP通知权限!',
showCancel: false,
success: function (res) {
if (res.confirm) {
var Intent = plus.android.importClass('android.content.Intent');
var intent = new Intent('android.settings.APP_NOTIFICATION_SETTINGS');
//可设置表中所有Action字段
intent.putExtra('android.provider.extra.APP_PACKAGE', pkName);
main.startActivity(intent);
}
}
});
}

相关文章

  • h5+plus 手动打开通知

    一、苹果 也可以这样写: 官方示例: 二、安卓代码

  • KVO的使用与底层探索

    1. 使用 1.1 自动通知 示例 1.2 手动通知 手动通知提供了更自由的方式去决定什么时间,什么方式去通知观察...

  • 如何在IOS手机上安装企业签名的应用

    手动安装和信任企业级应用 当您首次打开手动安装的企业级应用时,会看到一个通知,提示该应用的开发者在设备上不受信任。...

  • iOS8 通知设置

    无意中安装了钉钉,发现现在把提示的通知关闭后,进入首页会弹出来一个手动打开通知的办法,感觉以后也可能会遇见,分享大...

  • 怎样让uiautomatorviewer查看到android中的

    直接手动在android系统手动打开,webview页面,在用uiautomatorviewer识别页面元素,是无...

  • GitHub访问慢解决方案

    手动修改hosts文件(Mac): 1、打开hosts文件 打开Finder,commond + shift + ...

  • KVO原理

    KOV是利用KVC和通知共同实现的 自动发送通知 需要手动发送通知 在对象中实现反方 系统就不会发出通知了 底层实...

  • iOS KVO (2)KVO手动通知

    在写这篇文章之前,我对网上关于KVO手动通知的资源也进行了搜索,我能感觉到有些作者不了解这个知识,甚至把读者带入了...

  • KVO手动控制通知过程

    ■ 核心:当一个类有观察者时,生成一个中间类,把它的isa指向中间类。 (生成中间类就方便去重写它的set方法。K...

  • Key-Value-Observing OC&Swift

    KVC 支持实例变量,KVO 只能手动支持手动设定实例变量的KVO实现监听。KVO通过set方法来通知。或者KVC...

网友评论

      本文标题:h5+plus 手动打开通知

      本文链接:https://www.haomeiwen.com/subject/oxdchrtx.html