Azure / azure-mobile-engagement-cordova

MIT License
9 stars 15 forks source link

Incompatibility with phonegap-plugin-push on IOS #46

Closed gustavokloh closed 7 years ago

gustavokloh commented 7 years ago

Hi!

We have an app built with Ionic. And to receive push notifications we're using https://github.com/phonegap/phonegap-plugin-push .

The azure-mobile-engagement is used only to track some events.

After install azure-mobile-engagement my push notification doesn't work anymore. Do we have some incompatibily here?

How to proceed?

Is there a way to disable azure-mobile-engagement notifications behavior?

Thanks

gustavokloh commented 7 years ago

Just complementing. I think that should be related with Reach module. I disabled reach module manually and locally on code, and azure-mobile plugin still intercepting my notifications, instead I receive with phonegap-plugin-push

ogoguel commented 7 years ago

Can you confirm on which platform you have this issue ? I am assuming iOS...

As of today, you cannot prevent notifications from being received by the plugin, but notifications are normally forwarded to other instances, and the phonegap-push-plugin should eventually receive them. But they might be some incompatibility issue between both plugins. , I will investigate.

In the meantime, to disable the push notification support on iOS, just comment all the lines in the +(void)load function in AZMEcordova.m (the one containing the swizzleInstanceSelector lines) : let us know if it works for you

gustavokloh commented 7 years ago

Yes, on iOS. On Android everything works correctly.

I will try disable push notification support for now, thanks! And I'm waiting the investigation.

Thanks for reply

gustavokloh commented 7 years ago

hi @ogoguel !

I've tried to comment all the lines in the +(void)load as you recommend. And nothing.

I made some other tests to try to supply you other informations.

If a push notification is delivered and the app is closed, after tap notification the app opens correctly but the expected behavior implemented with phonegap-push-plugin doesn't happen and on the Xcode, below warning appears:

Warning: UNUserNotificationCenter delegate received call to -userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: but the completion handler was never called.

This test was executed with the lines commented.

Other information: we're using Ionic to build our app.

ogoguel commented 7 years ago

I did some quick test with the phonegap-push-plugin (version 1.9.2 from npm) and did not encounter any compatibility issue with the current AZME plugin : notification events are properly sent back and forth between plugins.

From your last feedback though, there might be a conflict with multiple UNUserNotificationCenter delegates but could not find such implementation in the push plugin. Could you confirm which version you are using and other push related plugins you might be using ? A full log might be helpful too.

Keeping investigating anyway...

gustavokloh commented 7 years ago

We're using plugins listed below:

com.telerik.plugins.nativepagetransitions 0.6.5 "Native Page Transitions"
cordova-plugin-crosswalk-webview 2.2.0 "Crosswalk WebView Engine"
cordova-plugin-customurlscheme 4.2.0 "Custom URL scheme"
cordova-plugin-device 1.1.4 "Device"
cordova-plugin-facebook4 1.7.4 "Facebook Connect"
cordova-plugin-inappbrowser 1.5.0 "InAppBrowser"
cordova-plugin-ms-azure-mobile-engagement 3.2.3 "Azure Mobile Engagement"
cordova-plugin-network-information 1.3.0 "Network Information"
cordova-plugin-splashscreen 4.0.0 "Splashscreen"
cordova-plugin-whitelist 1.3.0 "Whitelist"
ionic-plugin-keyboard 2.2.1 "Keyboard"
phonegap-plugin-push 1.9.2 "PushPlugin"

And our versions of platforms:

Cordova CLI: 6.4.0
Gulp version:  CLI version 1.2.2
Gulp local:   Local version 3.9.1
Ionic CLI Version: 1.7.14
OS: Mac OS X El Capitan
Node Version: v6.5.0
Xcode version: Xcode 8.2.1 Build version 8C1002

In your test, which event on push-plugin you've listened? Here we're using Ionic Push, so we listen $scope.$on("cloud:push:notification", function () {}) . This event is fired from Ionic wrapping on(notification) from push-plugin.

We will copy full log on iOS to provide you.

ogoguel commented 7 years ago

Here is my test code :

 $scope.onReady = function() {
  var push = PushNotification.init(
         { "ios": {"alert": "true", "badge": "true", "sound": "true"}, "windows": {} } );
        push.on('registration', function(data) {
            console.log("registration"+ data.registrationId);
        });
        push.on('notification', function(data) {
             console.log("notification"+ data.message);
        });
        push.on('error', function(e) {
             console.error("error "+ e.message);
        });
}

It is just a plain angular application (not using ionic 1) which retrieves the notification directly from the PushNotificationplugin. Also, for my test, the notification was being sent through the AZME service.

However, from your comment, it appears we did not test exactly the same thing :( Can you check if this sample code works for you ? If not, I would need to replicate your environment by using the ionic cloud service as the notification service, and ionic 1 as the base framework.

To be continued!

gustavokloh commented 7 years ago

Hi @ogoguel !

I've tested with your example but sending notifications through Ionic Cloud API, as we do on app. So I have a question. Are you send notification directly to device using registration Id frompush.on('registration')? How do you do to send push notification directly to device?

Thanks.

ogoguel commented 7 years ago

Not sure to get it : does my code work using the ionic cloud api ? In my case, I was using the AZME service to send a notification to my test device, as I assumed its behavior was equivalent to the ionic cloud service. cf. https://docs.microsoft.com/en-us/azure/mobile-engagement/mobile-engagement-ios-get-started#a-idsendasend-a-notification-to-your-app

ogoguel commented 7 years ago

I did some test with the ionic cloud, and I could reproduce your issue. As a quick fix, you can disable the notification support in AZMECordova.m by setting withReachEnabledto false.

 [[EngagementShared instance]   initialize:AZME_IOS_CONNECTION_STRING
                    withReachEnabled:[NSNumber numberWithBool:false] // Disable Reach
                   ...
}

Will modify the plugin to help you customize it. Thanks for your patience!

gustavokloh commented 7 years ago

Thanks a lot! I'll test it and give you feedback.

gustavokloh commented 7 years ago

Hey @ogoguel !

The suggested fix works with you? Can you receive push notification with data from Ionic Cloud?

I disabled the notification support as you said, and I have the same behavior :(

ogoguel commented 7 years ago

Yes : by setting withReachEnabledto false, notifications are received when sent from the ionic cloud. However, I've noticed that notifications are not received when the app is running. Still something to investigate

gustavokloh commented 7 years ago

@ogoguel yes! same here. Notifications are received but not handled.

Thanks

ogoguel commented 7 years ago

Finally, the issue seems to be linked to the UNUserNotificationCenterDelegate not being implemented in the Phonegap plugin... but present in the Engagement plugin.

Fortunately, a PR has been created to fix it (cf. https://github.com/phonegap/phonegap-plugin-push/pull/1279).

As it has not merged yet, just used the forked version from @Lucklyric (cordova add plugin https://github.com/Lucklyric/phonegap-plugin-push), and it should solve your issue!

(you don't even need to disable reach in the Engagement plugin!).

Hope it will work for your this time! Cheers

gustavokloh commented 7 years ago

Hey @ogoguel thanks for suggested solution.

I've worked on other things, and tested today.

I've installed phonegap-plugin-push as you said, and the behavior still the same. I removed current phonegap-plugin-push and installed that fork, so watching xcode logs I had this:

[Engagement-Plugin] ERROR: didFailToRegisterForRemoteNotificationsWithError Error Domain=NSCocoaErrorDomain Code=3000

myProject[2222:1885715] Push Plugin register failed

We can't register to receive push notifications with this install and Engagement plugin. To ensure this, I removed engagement plugin then I register and receive notifications normally even with suggested fork.

I'll try to figure out something on phonegap-push-plugin about new corrections.

Do you have the code to test as you suggested?

ogoguel commented 7 years ago

You error sounds like either a provisional profile issue, or missing capability in your project. cf. http://stackoverflow.com/questions/29440627/failed-to-get-token-error-error-domain-nscocoaerrordomain-code-3000-no-valid

Here's my minimal setup :

ionic start test
cd test
ionic plugin add cordova-plugin-ms-azure-mobile-engagement    --variable AZME_IOS_CONNECTION_STRING=$AZME_IOS_CONNECTION_STRING 
ionic plugin add https://github.com/Lucklyric/phonegap-plugin-push --variable SENDER_ID=$SENDER_ID

When triggering a notification, I can see these kind of logs in the console (in this test, the app was running in the background)

NotificationCenter Handle push from background or closed
app in-active
just put it in the shade
active
PushPlugin skip clear badge
[Engagement] Agent: UNUserNotificationCenter delegate of type 'AppDelegate' found.
Notification received

The important part is the warning from the Engagement plugin which shows that another notification center (ie: the one from the push plugin) has been registered

Hope it will work for you once you would have fixed your project settings!

gustavokloh commented 7 years ago

Hi @ogoguel I'll try to make this tests with a new project.