gpt4 book ai didi

ionic-framework - 如何在ionic 3的Onesignal中将默认推送通知图标更改为小图标?

转载 作者:行者123 更新时间:2023-12-04 23:36:33 31 4
gpt4 key购买 nike

我在 ionic 3 中更改小图标推送通知 Onesignal 时遇到问题,我尝试过本教程 https://documentation.onesignal.com/docs/customize-notification-iconshttps://ionicframework.com/docs/native/onesignal/https://github.com/OneSignal/OneSignal-Cordova-SDK/issues/341#issuecomment-382648188 ,但都失败了,我的推送通知中的小图标仍然默认为 onesignal。

这是我的文件夹结构和我的脚本:

我的文件夹结构 :

enter image description here

copy_android_notification_icons.js :

#!/usr/bin/env node

var fs = require('fs');
var path = require('path');

var rootDest = 'platforms/android/app/src/main/res';
var files = [{
'icon_onesignal/res/drawable-hdpi/ic_stat_onesignal_default.png':
path.join(rootDest, 'drawable-hdpi/ic_stat_onesignal_default.png')
}, {
'icon_onesignal/res/drawable-mdpi/ic_stat_onesignal_default.png':
path.join(rootDest, 'drawable-mdpi/ic_stat_onesignal_default.png')
}, {
'icon_onesignal/res/drawable-xhdpi/ic_stat_onesignal_default.png':
path.join(rootDest, 'drawable-xhdpi/ic_stat_onesignal_default.png')
}, {
'icon_onesignal/res/drawable-xxhdpi/ic_stat_onesignal_default.png':
path.join(rootDest, 'drawable-xxhdpi/ic_stat_onesignal_default.png')
}, {
'icon_onesignal/res/drawable-xxxhdpi/ic_stat_onesignal_default.png':
path.join(rootDest, 'drawable-xxxhdpi/ic_stat_onesignal_default.png')
}];

function createFolder(pathAbsolute) {
if (!fs.existsSync(pathAbsolute)) {
fs.mkdirSync(pathAbsolute);
}

console.log('Folder ready ', pathAbsolute);
}

module.exports = function(context) {
var root = context.opts.projectRoot;

createFolder(path.join(root, rootDest, 'drawable-hdpi'));
createFolder(path.join(root, rootDest, 'drawable-mdpi'));
createFolder(path.join(root, rootDest, 'drawable-xhdpi'));
createFolder(path.join(root, rootDest, 'drawable-xxhdpi'));
createFolder(path.join(root, rootDest, 'drawable-xxxhdpi'));

files.forEach(function(obj) {
Object.keys(obj).forEach(function(key) {
var src = path.join(root, key);
var dest = path.join(root, obj[key]);

if (fs.existsSync(src) && fs.existsSync(path.dirname(dest))) {
fs.createReadStream(src).pipe(fs.createWriteStream(dest));

console.log('Copied ' + src + ' to ' + dest);
}
});
});
};

app.components.ts

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';

import { HomePage } from '../pages/home/home';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage:any = HomePage;

constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();

var notificationOpenedCallback = function(jsonData) {
console.log('notificationOpenedCallback: ' + JSON.stringify(jsonData));
};

window["plugins"].OneSignal
.startInit("xxxx-yyyy-zzzz-123, "1234567")
.handleNotificationOpened(notificationOpenedCallback)
.endInit();
});
}
}

config.xml

<platform name="android">
<allow-intent href="market:*" />
<hook src="hooks/copy_android_notification_icons.js" type="after_prepare" />
</platform>

请更正我的文件夹或我的脚本,也许你发现了一个错误,请帮助解决这个问题。

谢谢。

最佳答案

您可以按照以下步骤操作。然后您无需触摸您的平台文件夹并手动添加推送通知图标。

  • 转至 Android Asset Studio并使用名称生成图标
    ic_stat_onesignal_default
  • 然后将这些图标复制到资源下的android文件夹中。就我而言
    它看起来像下面。

  • enter image description here
  • 然后在 config.xml 文件添加下面的代码。

  • <!-- Add to your existing android platform sction -->
    <platform name="android">
    <resource-file src="resources/android/notification/drawable-mdpi/ic_stat_onesignal_default.png" target="app/src/main/res/drawable-mdpi/ic_stat_onesignal_default.png" />
    <resource-file src="resources/android/notification/drawable-hdpi/ic_stat_onesignal_default.png" target="app/src/main/res/drawable-hdpi/ic_stat_onesignal_default.png" />
    <resource-file src="resources/android/notification/drawable-xhdpi/ic_stat_onesignal_default.png" target="app/src/main/res/drawable-xhdpi/ic_stat_onesignal_default.png" />
    <resource-file src="resources/android/notification/drawable-xxhdpi/ic_stat_onesignal_default.png" target="app/src/main/res/drawable-xxhdpi/ic_stat_onesignal_default.png" />
    <resource-file src="resources/android/notification/drawable-xxxhdpi/ic_stat_onesignal_default.png" target="app/src/main/res/drawable-xxxhdpi/ic_stat_onesignal_default.png" />
    </platform>
  • 构建项目
    再次。

  • 现在默认的推送通知图标将替换为新的。

    OneSignal DOC 查找更多详细信息

    关于ionic-framework - 如何在ionic 3的Onesignal中将默认推送通知图标更改为小图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52474275/

    31 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com