Pushwoosh / pushwoosh-phonegap-plugin

Pushwoosh PhoneGap Build Plugin
Other
109 stars 139 forks source link

Capacitor Support #290

Closed sandstrom closed 5 years ago

sandstrom commented 6 years ago

Curious to hear if you have verified if your plugin works with Capacitor (an open-source project based on, and similar to, Cordova)?

https://github.com/ionic-team/capacitor

wfhm commented 6 years ago

Hi,

We did not check if our plugin works with Capacitor yet. Have you already tried using the plugin with this framework on your own?

sandstrom commented 6 years ago

I haven't tried yet, but will do. I'll close this for now, I'll re-open if I run into any issues.

Thanks!

chintan13 commented 5 years ago

is this worked for anyone in capacitor?

sandstrom commented 5 years ago

@chintan13 I haven't tried yet, sorry 😄

chintan13 commented 5 years ago

Looks like its not working, can you reopen this issue?

sandstrom commented 5 years ago

@chintan13 I've reopened, but I think it would help if you'd add more details for the Pushwoosh team to troubleshoot.

chintan13 commented 5 years ago

For Android its working fine

For ios if npx cap sync not working then we just need to comment out or add target="config.xml" `

`

and then try to build from xcode and it gives below error

ld: library not found for -lPushwoosh clang: error: linker command failed with exit code 1 (use -v to see invocation)

wfhm commented 5 years ago

@chintan13 @sandstrom Capacitor framework is now supported starting with 7.12.0 release.

sandstrom commented 5 years ago

(for anyone who's curious, here is the PR that added support: https://github.com/Pushwoosh/pushwoosh-phonegap-plugin/pull/306)

ipehimanshu commented 1 year ago

hi @wfhm

can you please share few steps how to make it working ?

I mean what we need to follow steps,

like what file we need to put into android folder, what we need to edit for xcode/ios platform ,

Thanks a lot if you share some more info specially for capacitor

Thanks a lot

wfhm commented 1 year ago

@ipehimanshu I think I will drop a working sample on Github later this week. Meanwhile, may I ask you what particular issues did you have when trying to integrate the plugin?

ipehimanshu commented 1 year ago

Hi

Actually i am not able to get push in android when app already open and for ios we try to run app with xcode (real device) but it never received push, so i am not sure but we failed to make it working, same code working with cordova, so we really appreciate if you make one sample with capacitor for both platform

Thanks a lot

On Tue, Feb 21, 2023 at 4:12 PM wfhm @.***> wrote:

@ipehimanshu https://github.com/ipehimanshu I think I will drop a working sample on Github later this week. Meanwhile, may I ask you what particular issues did you have when trying to integrate the plugin?

— Reply to this email directly, view it on GitHub https://github.com/Pushwoosh/pushwoosh-phonegap-plugin/issues/290#issuecomment-1438252389, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGLK3BXOT4IIXO5FZGA3EADWYSLZXANCNFSM4E74HCLA . You are receiving this because you were mentioned.Message ID: @.***>

wfhm commented 1 year ago

@ipehimanshu If I understood you correctly, you just migrated your Cordova app to Capacitor, is that so? If yes, then it doesn't really make sense to create a sample, since the integration process is different.

Actually i am not able to get push in android when app already open This is actually the default behavior of our plugin. Could it be that you have previously installed the plugin in your Cordova app with the following variable?

--variable ANDROID_FOREGROUND_PUSH="true"

If so, you can do the same with Capacitor by adding this flag to capacitor.config.json:

"cordova": {
    "preferences": {
        "ANDROID_FOREGROUND_PUSH"=true
    }
  }

Alternatively, you can set the corresponding meta-data to AndroidManifest.xml directly:

<meta-data android:name="com.pushwoosh.foreground_push" android:value="true" />

and for ios we try to run app with xcode (real device) but it never received push

Could you please share us with the device console logs so we could check it on our side? Just launch the app from Xcode, subscribe for pushes, send a push and collect the log (even if no push is received)?

ipehimanshu commented 1 year ago

Hello

We already try

"cordova": { "preferences": { "ANDROID_FOREGROUND_PUSH"=true } }

but it never update AndroidManifest.xml because capacitor use capacitor-cordova-android-plugins and it also has AndroidManifest.xaml and i see it value never update manually [image: image.png]

If i edit manually that value as false to true, then it works but once i fire command like npx cap sync that xml file again update and it set value as false again.

So that is reason we are stuck

and if i try to add into android folder AndroidManifest.xml then it give error like merge resources meta data

Hope it will be more clear for you

FYI current we are using capacitor latest version (4)

Thank you

On Thu, Mar 2, 2023 at 2:21 PM wfhm @.***> wrote:

@ipehimanshu https://github.com/ipehimanshu If I understood you correctly, you just migrated your Cordova app to Capacitor, is that so? If yes, then it doesn't really make sense to create a sample, since the integration process is different.

Actually i am not able to get push in android when app already open This is actually the default behavior of our plugin. Could it be that you have previously installed the plugin in your Cordova app with the following variable?

--variable ANDROID_FOREGROUND_PUSH="true"

If so, you can do the same with Capacitor by adding this flag to capacitor.config.json:

"cordova": { "preferences": { "ANDROID_FOREGROUND_PUSH"=true } }

Alternatively, you can set the corresponding meta-data to AndroidManifest.xml directly:

and for ios we try to run app with xcode (real device) but it never received push

Could you please share us with the device console logs so we could check it on our side? Just launch the app from Xcode, subscribe for pushes, send a push and collect the log (even if no push is received)?

— Reply to this email directly, view it on GitHub https://github.com/Pushwoosh/pushwoosh-phonegap-plugin/issues/290#issuecomment-1451507985, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGLK3BWA6U46JCH3V6FJXODW2BNRHANCNFSM4E74HCLA . You are receiving this because you were mentioned.Message ID: @.***>

wfhm commented 1 year ago

[image: image.png] Looks like the image got lost:) Apparently, Capacitor does not support Cordova install variables at all: Capacitor does not support Cordova install variables, auto configuration, or hooks, due to our philosophy of letting you control your native project source code (meaning things like hooks are unnecessary). If your plugin requires variables or settings to be set, you'll need to apply those configuration settings manually by mapping between the plugin's plugin.xml and required settings on iOS and Android.

The plugin currently does not provide any other way to change this value, so you will have to manually do it in the plugin itself. You can find the plugin source code in your node_modules directory and modify the PushwooshNotificationServiceExtension class by replacing the code below

@Override
    protected boolean onMessageReceived(final PushMessage pushMessage) {
        PushNotifications.messageReceived(pushMessage.toJson().toString());
        return (!showForegroundPush && isAppOnForeground()) || super.onMessageReceived(pushMessage);
    }

with this:

@Override
    protected boolean onMessageReceived(final PushMessage pushMessage) {
        PushNotifications.messageReceived(pushMessage.toJson().toString());
        return super.onMessageReceived(pushMessage);
    }

We'll update the plugin to provide an easier option to control foreground notifications behavior, meanwhile, you can try the workaround above. If you give it a shot, please let us know about the results.

ipehimanshu commented 1 year ago

ok so @wfhm possible to create issue with capacitor team

here is image screenshot which i want to share https://prnt.sc/4NikmzKS15lZ

Thank you

wfhm commented 1 year ago

@ipehimanshu I don't think we need Capacitor team at this moment - the plugin's design was not adapted to Capacitor according to their guidelines, so it should be done on our side anyway.

ipehimanshu commented 1 year ago

ok got it

ipehimanshu commented 1 year ago

@wfhm i confirm like after edit that file it comes foreground push for android also

Thank you

ajisakson commented 8 months ago

I'd like to make note here that the Cordova Pushwoosh plugin will not automatically add the required intents to your AndroidManifest.xml, so you'll need to add them yourself. For me this meant putting the following somewhere within the tags:

`

<meta-data android:name="com.pushwoosh.notification_service_extension" android:value="com.pushwoosh.plugin.pushnotifications.PushwooshNotificationServiceExtension"/>
<meta-data android:name="com.pushwoosh.internal.plugin_provider" android:value="com.pushwoosh.plugin.internal.PhonegapPluginProvider"/>
<service android:exported="false" android:name="com.pushwoosh.plugin.pushnotifications.CustomFirebaseMessagingService">
  <intent-filter>
    <action android:name="com.google.firebase.MESSAGING_EVENT"/>
  </intent-filter>
</service>`

This will make sure that the documented Pushwoosh event listeners work and that you can receive the notification when the app is killed or in the background on Android.

enginseer-dev commented 7 months ago

@ajisakson, thank you for your comment! Please let me check it on my own and update docs or the plugin if required.

enginseer-dev commented 6 months ago

Hello, @ajisakson

Thank you for your patience.

We've integrated the Pushwoosh Cordova plugin in a sample Capacitor project. The necessary intents are automatically added to the AndroidManifest.xml during the build process, as verified in the decompiled APK: image

This ensures that push notifications are correctly received even when the app is in the background or killed.

Please let us know if there are any further questions or concerns.

ajisakson commented 6 months ago

@enginseer-dev Can you confirm if this is how it has and should have been working previously? Or is this a recent addition to the plugin?

Either way, glad to see it working as such and I will make sure on our next Capacitor project with Pushwoosh that this is the case and will report back if we still have issue.

Thanks!

wfhm commented 6 months ago

@ajisakson this is the expected behavior, and it's been there for quite a long time. The metadata and other components of our SDK are merged into the final application manifest during the build process, and it is done by Gradle, not by Cordova/Capacitor tools, so it's quite strange that you had to do it manually. Should you have the same issue in your new projects, please let us know and we'll look into this again, but for now everything seems to be working as expected.

ipehimanshu commented 6 months ago

Hello Team,

Is it fixed issue which i need to manually change

PushwooshNotificationServiceExtension.java (because capacitor not allow to change false to true as we need to always receive push for all cases) //return (!showForegroundPush && isAppOnForeground()) || super.onMessageReceived(pushMessage); return super.onMessageReceived(pushMessage);

On Fri, Dec 15, 2023 at 5:27 PM wfhm @.***> wrote:

@ajisakson https://github.com/ajisakson this is the expected behavior, and it's been there for quite a long time. The metadata and other components of our SDK are merged into the final application manifest during the build process, and it is done by Gradle, not by Cordova/Capacitor tools, so it's quite strange that you had to do it manually. Should you have the same issue in your new projects, please let us know and we'll look into this again, but for now everything seems to be working as expected.

— Reply to this email directly, view it on GitHub https://github.com/Pushwoosh/pushwoosh-phonegap-plugin/issues/290#issuecomment-1857770259, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGLK3BQ25WS6EI4DFR3KWIDYJQ3MNAVCNFSM4E74HCLKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBVG43TOMBSGU4Q . You are receiving this because you were mentioned.Message ID: @.***>

wfhm commented 6 months ago

@ipehimanshu you can set the ANDROID_FOREGROUND_PUSH plugin variable to true or false in your capacitor.config.json.

ipehimanshu commented 6 months ago

ok so will it automatic set true to androidmanifest.xml because so far i remember you says to me like edit some core files

@wfhm please show one example which is working like that with capacitor ?

enginseer-dev commented 6 months ago

@ipehimanshu I have tested and the flags aren't working yet. The following manual edit is still needed for the foreground push notifications to work:

You can find the plugin source code in your node_modules directory and modify the PushwooshNotificationServiceExtension class by replacing the code below

@Override
protected boolean onMessageReceived(final PushMessage pushMessage) {
PushNotifications.messageReceived(pushMessage.toJson().toString());
return (!showForegroundPush && isAppOnForeground()) || super.onMessageReceived(pushMessage);
}

with this:

@Override
protected boolean onMessageReceived(final PushMessage pushMessage) {
PushNotifications.messageReceived(pushMessage.toJson().toString());
return super.onMessageReceived(pushMessage);
}

We will look into this issue and will fix it in the next release.

ipehimanshu commented 6 months ago

ok please

Thank you

On Tue, Dec 26, 2023 at 3:44 PM Enginseer @.***> wrote:

@ipehimanshu https://github.com/ipehimanshu I have tested and the flags aren't working yet. The following manual edit is still needed for the foreground push notifications to work:

You can find the plugin source code in your node_modules directory and modify the PushwooshNotificationServiceExtension https://github.com/Pushwoosh/pushwoosh-phonegap-plugin/blob/master/src/android/src/com/pushwoosh/plugin/pushnotifications/PushwooshNotificationServiceExtension.java class by replacing the code below

@Override protected boolean onMessageReceived(final PushMessage pushMessage) { PushNotifications.messageReceived(pushMessage.toJson().toString()); return (!showForegroundPush && isAppOnForeground()) || super.onMessageReceived(pushMessage); }

with this:

@Override protected boolean onMessageReceived(final PushMessage pushMessage) { PushNotifications.messageReceived(pushMessage.toJson().toString()); return super.onMessageReceived(pushMessage); }

We will look into this issue and will fix it in the next release.

— Reply to this email directly, view it on GitHub https://github.com/Pushwoosh/pushwoosh-phonegap-plugin/issues/290#issuecomment-1869432807, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGLK3BTSHOZKYNLD763NWLTYLKPQBAVCNFSM4E74HCLKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBWHE2DGMRYGA3Q . You are receiving this because you were mentioned.Message ID: @.***>

enginseer-dev commented 4 months ago

Hello, @ipehimanshu

We've released a new version of the Cordova plugin 8.3.23 and added setShowPushnotificationAlert method. The method allows you to configure the display of push notifications while the app is in the foreground by setting it to either false or true.

Example:

function initPushwoosh() {
    var pushwoosh = cordova.require("pushwoosh-cordova-plugin.PushNotification");

    // Should be called before pushwoosh.onDeviceReady
    document.addEventListener('push-notification', function(event) {
        var notification = event.notification;
        // Handle push open here
        console.log('Received push notification: ', notification);
    });

    // Initialize Pushwoosh. This will trigger all pending push notifications on start.
    pushwoosh.onDeviceReady({
        appid: "APP_CODE",
        projectid: "SENDER_ID",
        serviceName: "MPNS_SERVICE_NAME" // Omit this if not using MPNS
    });

    // Registering for push notifications
    pushwoosh.registerDevice(
        function(status) {
            var pushToken = status.pushToken;
            // Handle successful registration here
            console.log('Push token received: ', pushToken);
        },
        function(status) {
            // Handle registration error here
            console.error('Push registration failed: ', status);
        }
    );

    pushwoosh.setShowPushnotificationAlert(true);
}