I am creating an ionic-angular app. I tried to use push notification with the capacitor plugin. But I got an error like this. Can anyone help me?
**"ERROR Error: Uncaught (in promise): Error: "PushNotifications" plugin is not implemented on android
Error: "PushNotifications" plugin is not implemented on android"**
I resolved "ERROR Error: Uncaught (in promise): Error: "PushNotifications" plugin is not implemented on android
Error: "PushNotifications" plugin is not implemented on android" error please follow below step
Add google-service.json file inside android/app folder
add this code in .ts file
import {
ActionPerformed,
PushNotificationSchema,
PushNotifications,
Token,
} from '#capacitor/push-notifications';
import { Platform } from '#ionic/angular';
constructor(public platform: Platform) {
this.platform.ready().then(() => {
this.pushAdded();
})
}
pushAdded() {
// Request permission to use push notifications
// iOS will prompt user and return if they granted permission or not
// Android will just grant without prompting
PushNotifications.requestPermissions().then(result => {
if (result.receive === 'granted') {
// Register with Apple / Google to receive push via APNS/FCM
PushNotifications.register();
} else {
// Show some error
}
});
PushNotifications.addListener('registration', (token: Token) => {
alert('Push registration success, token: ' + token.value);
});
PushNotifications.addListener('registrationError', (error: any) => {
alert('Error on registration: ' + JSON.stringify(error));
});
PushNotifications.addListener(
'pushNotificationReceived',
(notification: PushNotificationSchema) => {
alert('Push received: ' + JSON.stringify(notification));
},
);
PushNotifications.addListener(
'pushNotificationActionPerformed',
(notification: ActionPerformed) => {
alert('Push action performed: ' + JSON.stringify(notification));
},
);
}
I have fixed this issue by removing the android folder and re-add that. Then it worked. Thanks, Ravi Ashara for helping.
Check your MainActivity.java within your project. In the last version of Capacitor you have to remove the code "onCreate".
See: https://capacitorjs.com/docs/updating/3-0#switch-to-automatic-android-plugin-loading
Related
I have an Ionic 5 app with Capacitor 3 and I'm trying to receive notifications using Firebase Cloud messaging, on an Android device. I followed the configurations,(I downloaded the google JSON file and put my app id name correctly ) and I'm getting correctly the device token. Once my app is open I get the token successfully without any error and then I send a notification sharing my token to the Firebase test message, the notification never arrived, and also I never get an error of push notification in my logger. This is the code that I use for push notification.
export class PushNotificationsService {
constructor(private readonly http: HttpClient, private notificationState: NotificationsStore) { }
public initPush() {
if (Capacitor.getPlatform() !== 'web') {
this.registerPush();
}
}
private registerPush() {
PushNotifications.requestPermissions().then(async result => {
if (result.receive === 'granted') {
// Register with Apple / Google to receive push via APNS/FCM
console.log('granted');
await PushNotifications.register();
} else {
// Show some error
console.log('errorr');
}
});
// On success, we should be able to receive notifications
PushNotifications.addListener('registration',
(token: Token) => { (I get through this step and access the token successfully)
console.log('Push registration success, token: ' + token.value);
this.notification state.setToken(token.value);
}
);
// I never get this step error
PushNotifications.addListener('registrationError',
(error: any) => {
console.log('Error on registration: ' + JSON.stringify(error));
}
);
PushNotifications.addListener('pushNotificationReceived',
(notification: PushNotificationSchema) => {
console.log('Push received: ' + JSON.stringify(notification));
}
);
PushNotifications.addListener('pushNotificationActionPerformed',
(notification: ActionPerformed) => {
console.log('Push action performed: ' + JSON.stringify(notification));
}
);
}
I also have capacitor.config.json like this:
"PushNotifications": {
"presentationOptions": ["badge", "sound", "alert"]
}
Also, I checked that my device and app have permission for notifications and are enabled both. I tried and test this issue with my app open and closed and open only in the background and the notification never arrives. What it could be? Any clue? Thank you
Android Phone Please Create the channel Like this, Test or Add screenshot for console Error
if (Capacitor.getPlatform() === 'android') {
PushNotifications.createChannel({
id: 'fcm_default_channel',
name: 'app name',
description: 'Show the notification if the app is open on your device',
importance: 5,
visibility: 1,
lights: true,
vibration: true,
});
}
I'm having issues trying to get the InAppPurchases to work in my React Native app using Expo. https://docs.expo.io/versions/latest/sdk/in-app-purchases
This is a bare workflow app that I ejected from a standard Expo app.
I made sure to follow the install instructions here carefully: https://docs.expo.io/bare/installing-unimodules/
I did test if unimodules was properly installed:
import { Constants } from "react-native-unimodules";
useEffect(() => {
alert("installed: " + JSON.stringify(Constants.systemFonts));
}, []);
The code above worked.
I'm using react-native-unimodules version 0.11.0.
Here's my code:
useEffect(() => {
(async function init() {
try {
const connect_res = await connectAsync();
alert("connect: " + JSON.stringify(connect_res));
} catch (err) {
alert("general error for connect async: " + err);
}
})();
}, []);
This is in the App.js entrypoint file. It always returns undefined for the connect_res so I assume this is the reason why I couldn't get any of the code to work.
Just below connectAsync() I have the following. This one also doesn't return anything:
setPurchaseListener(({ responseCode, results, errorCode }) => {
if (responseCode === IAPResponseCode.OK) {
results.forEach((purchase) => {
if (!purchase.acknowledged) {
alert("purchase successful!");
finishTransactionAsync(purchase, true);
}
});
}
if (responseCode === IAPResponseCode.USER_CANCELED) {
alert("user cancelld!");
} else if (responseCode === IAPResponseCode.DEFERRED) {
alert("user does not have permission to buy");
} else {
alert("something went wrong: " + errorCode);
}
});
Then on my payment screen I have the following:
import { getProductsAsync, purchaseItemAsync } from "expo-in-app-purchases";
This is the code for the payment button:
const makePayment = async () => {
alert("now making payment...");
try {
const items = Platform.select({
ios: ["abc"],
android: ["my-sub-id", "sku-my-sub-id"],
});
alert("items: " + JSON.stringify(items));
const products = await getProductsAsync(items);
alert("products: " + JSON.stringify(products));
if (products.results.length > 0) {
alert("found products!");
await purchaseItemAsync("my-sub-id");
alert("done making payment!");
} else {
alert("no products..");
}
} catch (err) {
alert("error occured while trying to purchase: " + err);
}
};
In this case, getProductsAsync() does return something resembling the format the results should be. But it doesn't return any of the subscriptions I created (I copied the product ID value listed in that column and I supplied it to both getProductsAsync and purchaseItemAsync. I also supplied the url version which basically just has a prefix of sku-:
I also enabled licensing testing for the email I'm using in Google Play:
Do note that I'm uploading the .aab file to Google Play on the internal testing track then I install it using this URL format: https://play.google.com/apps/test/com.myname.appname/versionNumber
But when I open that link, it seems like google play is detecting it as an old version even though its the latest one. The changes I've made shows up though so I'm pretty sure that's the correct install URL.
What else could I be missing?
For anyone having the same problem. all you have to do is add this on your android/app/src/main/AndroidManifest.xml file:
<uses-permission android:name="com.android.vending.BILLING" />
It wasn't mentioned in the docs at the time of this post, and it doesn't get automatically added when you install a module. Might help save you the headache if you assume the same is true for all Expo modules.
I'm trying to add notification with firebase in my ionic application (ionic 5). I follow this tutorial : https://www.positronx.io/ionic-firebase-fcm-push-notification-tutorial-with-example/
I recieve the token and when i send a notification from firebase console, the notification is displayed on the phone (emulator) but nothing is displayed in the console to handle the notification click...
I add FCM into provides in app.modules.ts and i have added the following code in the app.component.ts
import { FCM } from "#ionic-native/fcm/ngx";
...
constructor(
...
private fcm: FCM
) {}
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
this.fcm.getToken().then(token => {
console.log(token);
});
this.fcm.onTokenRefresh().subscribe(token => {
console.log(token);
});
this.fcm.onNotification().subscribe(data => {
console.log(data);
if (data.wasTapped) {
console.log('Received in background');
} else {
console.log('Received in foreground');
}
});
if (token === null) {
this.msgService.presentToast(
"Impossible de configurer la reception des notifications"
);
}
// Observer.hasTokenFCM.next(token);
if (this.platform.is("ios") || this.platform.is("android")) {
// this.saveToken(token);
}
});
And a have installed the following plugins:
ionic cordova plugin add cordova-plugin-fcm-with-dependecy-updated
npm install #ionic-native/fcm
cordova plugin list:
cordova-plugin-fcm-with-dependecy-updated 4.4.0 "Cordova FCM Push Plugin"
In my package.json:
dependencies:
"#ionic-native/fcm": "^5.22.0",
"cordova-plugin-fcm-with-dependecy-updated": "^4.1.1",
"cordova" -> "plugins":
"cordova-plugin-fcm-with-dependecy-updated": {
"FCM_CORE_VERSION": "16.0.8",
"FCM_VERSION": "18.0.0",
"GRADLE_TOOLS_VERSION": "2.3.+",
"GOOGLE_SERVICES_VERSION": "3.0.0"
},
Thanks a lot if you found why the "this.fcm.onNotification.subscribe" is never fired...
To fix this, use cordova-plugin-fcm-with-dependecy-updated plugin instead of #ionic-native/fcm/ngx, they are conflicting with each other. If onNotification method is not fired and you can't get the payload, try to use getInitialPushPayload
...
const pushPayload = await this.fcm.getInitialPushPayload();
if (pushPayload) {
this.processPayload(pushPayload);
}
this.fcm.onNotification().subscribe(
(payload: PushNotification) => this.processPayload(payload)
);
...
apparently i need to use
this.firebase.onMessageReceived().subscribe(notification => {
if (notification["tap"]) {
...
}
....
});
with firebase plugin to handle notification... but i don't know why.
I am building an Ionic Android/IOS app which includes push notifications from firebase cloud messaging. However, I am having problems with retrieving the token.
I have tried a couple of variations but they all lead to errors.
...
import { FCM } from '#ionic-native/fcm/ngx';
import { AngularFireMessaging } from '#angular/fire/messaging';
import { Firebase } from '#ionic-native/firebase/ngx';
#Injectable()
export class FcmNotificationProvider {
constructor(
public firebaseNative : Firebase,
public afs: AngularFirestore,
public afMessaging : AngularFireMessaging,
private platform: Platform,
private fcm: FCM
) {}
getToken() {
this.fcm.getToken
.subscribe(
(token) => { alert('We got a token', token); },
(error) => { alert(error); },
);
}}
// gives an error
Error: Uncaught (in promise): TypeError: Object(...) is not a function
TypeError: Object(...) is not a function
I also tried using AngularFireMessaging and got a different error when running on my android device.
this.afMessaging.getToken
.subscribe(
(token) => { alert('We got a token', token); },
(error) => { alert(error); },
);
When I install and run the apk on my device i get the following error: "This browser doesnt support the API's required to use the firebase SDK. (messaging/unsupported-browser).
Any ideas on what I am doing wrong here?
I'm using react-native for facebook log in. As you can see on the following link, i have some problem with the facebook login render:
To get that, first i did : rnpm install react-native-fbsdk (to install facebook dependencies).
Then I added the basics facebook code tutorial (https://developers.facebook.com/docs/react-native/login) :
const FBSDK = require('react-native-fbsdk');
const {
LoginButton,
} = FBSDK;
var Login = React.createClass({
render: function() {
return (
<View>
<LoginButton
publishPermissions={["publish_actions"]}
onLoginFinished={
(error, result) => {
if (error) {
alert("Login failed with error: " + result.error);
} else if (result.isCancelled) {
alert("Login was cancelled");
} else {
alert("Login was successful with permissions: " + result.grantedPermissions)
}
}
}
onLogoutFinished={() => alert("User logged out")}/>
</View>
);
}
});
Finally I added my Facebook API Key in the android manifest like that :
(meta-data) android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/>
Do you have any idea to solve this problem ? Thanks a lot for your answers !
I found the solution...
The problem was coming from MainApplication.java and MainActivity.java (in android/app).
Facebook's documentation is out of date... (only available for react-native version < 0.29...).