• 0
  • 0

Uniapp IOS 检测是否开启消息通知

2020-03-13 743 0 admin 所属分类:Hbuilder

如果没有开启,指引前去打开消息通知

function isOpenPush() {
    var UIApplication = plus.ios.import("UIApplication");
    var app = UIApplication.sharedApplication();
    var enabledTypes = 0;
    if (app.currentUserNotificationSettings) {
        var settings = app.currentUserNotificationSettings();
        enabledTypes = settings.plusGetAttribute("types");
        console.log("enabledTypes1:" + enabledTypes);
        if (enabledTypes == 0) {
            plus.nativeUI.confirm("推送设置没有开启,是否去开启?", function(e) {
                if (e.index == 0) {
                    var NSURL2 = plus.ios.import("NSURL");
                    var setting2 = NSURL2.URLWithString("app-settings:");
                    var application2 = UIApplication.sharedApplication();
                    application2.openURL(setting2);
                    plus.ios.deleteObject(setting2);
                    plus.ios.deleteObject(NSURL2);
                    plus.ios.deleteObject(application2);
                }
            }, {
                "buttons": ["前往", "不去"],
                "verticalAlign": "center"
            });
        }
        plus.ios.deleteObject(settings);
    } else {
        enabledTypes = app.enabledRemoteNotificationTypes();
        if (enabledTypes == 0) {
            console.log("推送未开启!");
        } else {
            console.log("已经开启推送功能!")
        }
        console.log("enabledTypes2:" + enabledTypes);
    }
    plus.ios.deleteObject(app);
}


返回顶部