master
chen 2022-08-18 14:21:46 +08:00
parent 65235bf13d
commit c2bfc1c66a
4 changed files with 97 additions and 10 deletions

67
App.vue
View File

@ -15,6 +15,7 @@
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
this.globalData.bgmMusic = wx.createInnerAudioContext(); this.globalData.bgmMusic = wx.createInnerAudioContext();
// #endif // #endif
this.checkNotification();
}, },
onShow: function() { onShow: function() {
if(uni.getStorageSync('token')){ if(uni.getStorageSync('token')){
@ -31,7 +32,71 @@
}, },
methods:{ 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> </script>

4
jsFile/push.js Normal file
View File

@ -0,0 +1,4 @@
// 原生检测
export default {
}

View File

@ -17,34 +17,36 @@
"delay" : 0 "delay" : 0
}, },
/* */ /* */
"modules" : {}, "modules" : {
"Push" : {}
},
/* */ /* */
"distribute" : { "distribute" : {
/* android */ /* android */
"android" : { "android" : {
"permissions" : [ "permissions" : [
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>", "<uses-feature android:name=\"android.hardware.camera\"/>",
"<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.autofocus\"/>", "<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/>", "<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_FINE_LOCATION\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_MOCK_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_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.CAMERA\"/>", "<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_ACCOUNTS\"/>",
"<uses-permission android:name=\"android.permission.GET_TASKS\"/>", "<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.MODIFY_AUDIO_SETTINGS\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>", "<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_EXTERNAL_STORAGE\"/>",
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>", "<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>", "<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.WAKE_LOCK\"/>",
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>", "<uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\"/>",
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>" "<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
] ]
}, },
@ -60,6 +62,12 @@
"appkey_ios" : "", "appkey_ios" : "",
"appkey_android" : "" "appkey_android" : ""
} }
},
"push" : {
"unipush" : {
"version" : "2",
"offline" : true
}
} }
} }
} }

View File

@ -423,6 +423,7 @@
// this.offMusic(); // this.offMusic();
if(uni.getStorageSync('ifVoice')){ if(uni.getStorageSync('ifVoice')){
console.log('进入接收消息'); console.log('进入接收消息');
this.createMessage();
// uni.showToast({ // uni.showToast({
// title:'' // title:''
// }) // })
@ -449,6 +450,15 @@
}); });
// #endif // #endif
}, },
//
createMessage(){
uni.createPushMessage({
title:'你好Y',
content:'这是测试内容',
icon:'/static/public/icon-plan-fire.png',
cover:true //
})
},
// //
bofang(msg){ bofang(msg){
this.bgmMusic.autoplay = true;// this.bgmMusic.autoplay = true;//