master
parent
65235bf13d
commit
c2bfc1c66a
67
App.vue
67
App.vue
|
@ -15,6 +15,7 @@
|
|||
// #ifdef MP-WEIXIN
|
||||
this.globalData.bgmMusic = wx.createInnerAudioContext();
|
||||
// #endif
|
||||
this.checkNotification();
|
||||
},
|
||||
onShow: function() {
|
||||
if(uni.getStorageSync('token')){
|
||||
|
@ -31,7 +32,71 @@
|
|||
|
||||
},
|
||||
methods:{
|
||||
|
||||
/**
|
||||
* 检测通知栏
|
||||
*/
|
||||
checkNotification:function(){
|
||||
if(plus.os.name.toLowerCase() == 'ios'){
|
||||
this.checkIosNotification();
|
||||
}
|
||||
else{
|
||||
this.checkAndroidNotification();
|
||||
}
|
||||
},
|
||||
checkAndroidNotification:function(){
|
||||
var main = plus.android.runtimeMainActivity();
|
||||
var pkName = main.getPackageName();
|
||||
var NotificationManagerCompat = plus.android.importClass("android.support.v4.app.NotificationManagerCompat");
|
||||
var packageNames = NotificationManagerCompat.from(main);
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
checkIosNotification:function(){
|
||||
var UIApplication = plus.ios.import("UIApplication");
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
// 原生检测
|
||||
export default {
|
||||
|
||||
}
|
|
@ -17,34 +17,36 @@
|
|||
"delay" : 0
|
||||
},
|
||||
/* 模块配置 */
|
||||
"modules" : {},
|
||||
"modules" : {
|
||||
"Push" : {}
|
||||
},
|
||||
/* 应用发布信息 */
|
||||
"distribute" : {
|
||||
/* android打包配置 */
|
||||
"android" : {
|
||||
"permissions" : [
|
||||
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
|
||||
"<uses-feature android:name=\"android.hardware.camera\"/>",
|
||||
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
|
||||
"<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/>",
|
||||
"<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\"/>",
|
||||
"<uses-permission android:name=\"android.permission.ACCESS_MOCK_LOCATION\"/>",
|
||||
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
|
||||
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
|
||||
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.GET_TASKS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.INTERNET\"/>",
|
||||
"<uses-permission android:name=\"android.permission.MODIFY_AUDIO_SETTINGS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.READ_EXTERNAL_STORAGE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
|
||||
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
|
||||
"<uses-feature android:name=\"android.hardware.camera\"/>",
|
||||
"<uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
|
||||
]
|
||||
},
|
||||
|
@ -60,6 +62,12 @@
|
|||
"appkey_ios" : "",
|
||||
"appkey_android" : ""
|
||||
}
|
||||
},
|
||||
"push" : {
|
||||
"unipush" : {
|
||||
"version" : "2",
|
||||
"offline" : true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -423,6 +423,7 @@
|
|||
// this.offMusic();
|
||||
if(uni.getStorageSync('ifVoice')){
|
||||
console.log('进入接收消息');
|
||||
this.createMessage();
|
||||
// uni.showToast({
|
||||
// title:'您有新消息!'
|
||||
// })
|
||||
|
@ -449,6 +450,15 @@
|
|||
});
|
||||
// #endif
|
||||
},
|
||||
// 创建本地通知栏消息
|
||||
createMessage(){
|
||||
uni.createPushMessage({
|
||||
title:'你好Y',
|
||||
content:'这是测试内容',
|
||||
icon:'/static/public/icon-plan-fire.png',
|
||||
cover:true // 是否覆盖上一次提示的消息
|
||||
})
|
||||
},
|
||||
// 播放音乐
|
||||
bofang(msg){
|
||||
this.bgmMusic.autoplay = true;//自动播放
|
||||
|
|
Loading…
Reference in New Issue