Skip to content

Commit

Permalink
fix(push): remove setAutoNotification
Browse files Browse the repository at this point in the history
  • Loading branch information
fxy060608 committed Jul 10, 2023
1 parent 9ff66ca commit 27533bd
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/uni-cli-shared/lib/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ module.exports = {
: 'import \'@dcloudio/uni-stat/dist/uni-stat.es.js\';'
},
getPlatformPush () {
if (process.env.UNI_PUSH_V2_OFFLINE || process.env.UNI_PUSH_V1) {
if (process.env.UNI_PUSH_V1) {
return ';import \'@dcloudio/vue-cli-plugin-uni/packages/uni-push/dist/uni-push-v1.plus.es.js\';'
} else if (process.env.UNI_PUSH_V2_OFFLINE) {
return ';import \'@dcloudio/vue-cli-plugin-uni/packages/uni-push/dist/uni-push.plus.es.js\';'
} else if (process.env.UNI_PUSH_V2) {
return ';import \'@dcloudio/vue-cli-plugin-uni/packages/uni-push/dist/uni-push.es.js\';'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
function initPushNotification() {
// 仅 App 端
if (typeof plus !== 'undefined' && plus.push) {
plus.globalEvent.addEventListener('newPath', ({ path }) => {
if (!path) {
return;
}
// 指定的页面为当前页面
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
if (currentPage &&
currentPage.$page &&
currentPage.$page.fullPath === path) {
return;
}
// 简单起见,先尝试 navigateTo 跳转,失败后,再尝试 tabBar 跳转
uni.navigateTo({
url: path,
fail(res) {
if (res.errMsg.indexOf('tabbar') > -1) {
uni.switchTab({
url: path,
fail(res) {
console.error(res.errMsg);
},
});
}
else {
console.error(res.errMsg);
}
},
});
});
}
}

// @ts-expect-error
uni.invokePushCallback({
type: 'enabled',
offline: true,
});
Promise.resolve().then(() => {
initPushNotification();
});

0 comments on commit 27533bd

Please sign in to comment.