Open barmarko27 opened 6 years ago
That is because the file at phonegap-plugin-push/types/index.d.ts
which has the type definition for this plugin's API has not been updated to include the createChannel
method.
That was supposed to be a task assigned to me, but I haven't found the time to go back to it and do it recently, for there are a few other points I need to review to fully sync the typings with the API proper. PRs are welcome ;).
A sad workaround is to cast the PushNotification
object to <any>
on that call.
Hi, thanks for your feedback!
I've tried in this way, but the app don't start.
In the Google Chrome console I got this error: main.js:1507 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'createChannel' of undefined TypeError: Cannot read property 'createChannel' of undefined
` var channelId = "reminders";
var PushNotification: any;
PushNotification.createChannel(
function() { console.log("Successfully created notification channel: " + channelId); },
function() { console.log("Failed while attempting to create notification channel: " + channelId); },
{
id: channelId,
description: "Reminders",
importance: 4, // high importance
sound: "sounddefault" // plays alarm_1.wav in the res/raw folder
}
);
let push = PushNotification.init({
android: {
senderID: 'XXXXXXXXXXX',
forceShow: true
},
ios: {
alert: "true",
badge: true,
sound: 'true'
},
windows: {}
});`
When you do var PushNotification: any;
, you're overriding/hiding the original value of the global PushNotification
object with undefined
(your variable is unassigned).
Try var PushNotification: any = <any> PushNotification;
.
I am having a similar issue, except my problem occurs at runtime instead of during building. I am using (this.Push as any).createChannel(..), and that allows the project to build without errors, but when I run the app, I get "TypeError: this.Push.createChannel is not a function"
Just to make sure I'm not messing up anything with the way I cast Push to any, I removed the createChannel function from my code and did (this.Push as any).init(..) and that runs just fine, so I know that the any cast isn't messing it up, because the .init function works properly that way.
As an alternate method, I used "var PushNotification: any =
Perhaps this simply will not work at all until the types/index.d.ts file is updated?
I'm not sure your issue is exactly the same, @uj. Casting the PushNotification object to <any>
should allow any call/access on it to fall through to the original value that goes on the javascript runtime, which should always work because there's no type information whatsoever leftover from typescript during runtime (typescript is a compile-time-only language).
Anyway, that's just my guess. We need to update the type definitions soon, regardless of anything.
Expected Behaviour
Implementation of channel in ionic2 app
Actual Behaviour
Method createChannel not found in PushNotificationStatic
Reproduce Scenario (including but not limited to)
Added the createChannel before call init method into my app
Steps to Reproduce
Platform and Version (eg. Android 5.0 or iOS 9.2.1)
Android 8.0.0
(Android) What device vendor (e.g. Samsung, HTC, Sony...)
Nexus 6P
Cordova CLI version and cordova platform version
Plugin version
Sample Push Data Payload
{ "registration_ids": [""], "data": { "message": "Test message", "title": "Title", "soundname": "sounddefault", // for Android versions < 8.0 (API Level < 26) "android_channel_id": "reminders", } }
Sample Code that illustrates the problem
Logs taken while reproducing problem