如果需要判断ios系统推送功能是否开启,并提醒去设置页打开设置推送,可以用以下nativeJS 代码:
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": ["Yes", "No"],
"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);
}
此功能在uniapp项目且配置为自定义模式的时候,会报:“plus.ios.import is not a function”错误。
该问题已经在HBuilderX1.9.4.20190426 之后版本已经解决
23 个评论
要回复文章请先登录或注册
8***@qq.com
9***@qq.com
CLP (作者)
q***@163.com
q***@163.com
CLP (作者)
q***@163.com
q***@163.com
CJoey
GUNDAM