在我的 nativescript 应用程序中,我使用 nativescript-local-notifications NPM来推送本地通知,并且我按照与 github 中的自述文件相同的说明进行操作。
我面临错误
LocalNotifications.schedule:TypeError:builder.setChannelId 不是函数
我提到了已经被某人解决的 GitHub 问题。但是,我仍然面临这个问题。
项目组件.ts:
import * as LocalNotifications from "nativescript-local-notifications";
scheduleTesting() {
console.log("I am inside schedule noti");
LocalNotifications.hasPermission().then(
function (granted) {
console.log("Permission granted -->" + granted);
}
)
LocalNotifications.schedule([{
id: 0,
title: 'Sound & Badge',
body: 'Who needs a push service anyway?',
badge: 1,
at: new Date(new Date().getTime() + (5 * 1000)) // 5 seconds from now
}])
LocalNotifications.addOnMessageReceivedCallback(data => {
alert({
title: "Local Notification received",
message: `id: '${data.id}', title: '${data.title}'.`,
okButtonText: "Roger that"
});
});
}
宣言XML
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="__PACKAGE__"
android:versionCode="1"
android:versionName="1.0">
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"/>
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="__APILEVEL__"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name="com.tns.NativeScriptApplication"
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name="com.tns.NativeScriptActivity"
android:label="@string/title_activity_kimera"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/LaunchScreenTheme"
android:launchMode="singleTop"
>
<meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity>
<activity
android:name="com.tns.ErrorReportActivity"/>
</application>
</manifest>
API 级别 = 27 "nativescript-local-notifications": "^2.0.3",
GITHub 问题网址:https ://github.com/EddyVerbruggen/nativescript-local-notifications/pull/68