Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not receiving property "tap" IOS #61

Closed
mateusduraes opened this issue Jul 26, 2019 · 26 comments
Closed

Not receiving property "tap" IOS #61

mateusduraes opened this issue Jul 26, 2019 · 26 comments
Labels
ios relates to iOS platform runtime issue An issue related to app runtime

Comments

@mateusduraes
Copy link

mateusduraes commented Jul 26, 2019

Hi

This plugins seems to work fine. I'm testing my app IOS app in development mode.
I receive the notifications that i send from firebase console, but, when the app is closed and I tap the notification, the app opens but there is no information about the property tap.

Those are the only informations that I receive

aps: {alert: {title: "Be Tester", body: "Hello, how are you?"}}
foo: "bar"
gcm.message_id: "1564165799854825"
gcm.n.e: "1"
google.c.a.c_id: "7897239349476441347"
google.c.a.e: "1"
google.c.a.ts: "1564165799"
google.c.a.udt: "0"
messageType: "notification"

Can someone give me help?

@metinjakupi
Copy link

Same problem here

@dpa99c
Copy link
Owner

dpa99c commented Jul 27, 2019

I'm not able to reproduce this issue when testing using the example project with the latest version (6.0.2) of this plugin.

This screen capture shows the ios_notification_custom_sound_and_badge.json message being sent via the FCM v1 API using the client in the test project.

This screen capture shows a notification message sent from the Firebase Console with the notification_foreground: true key in the data payload.

In both, there a 3 scenarios illustrated:

  • 1: Notification message arrives while app is running in foreground and notification is tapped
  • 2: Notification message arrives while app is running in background and notification is tapped
  • 2: Notification message arrives while app is not running (has been task killed) and notification is tapped

As you'll see, in all situations the tap key is present with the expected value.

I would urge you to repeat the same tests as above by building and running the example project and report your results here.

@dpa99c dpa99c added awaiting response If no response, issue will be closed ios relates to iOS platform runtime issue An issue related to app runtime labels Jul 27, 2019
@mateusduraes
Copy link
Author

mateusduraes commented Jul 29, 2019

Hi @dpa99c, thank you so much for the feedback so quickly.
It worked like a charm in the test project but i still have problems in my project.

I will make some investigations and let you know. I believe you can close the issue for now.

@metinjakupi
Copy link

@mateusduraes use this body https://github.com/dpa99c/cordova-plugin-firebasex-test/blob/master/messages/notification.json, i had the same problem for iOS but using this body fixed and now it works

@dpa99c
Copy link
Owner

dpa99c commented Jul 29, 2019

@mateusduraes thanks for the update. will close for now.

@dpa99c dpa99c closed this as completed Jul 29, 2019
@mateusduraes
Copy link
Author

Hi, after some debug i realize that i still not receiving the property tap.
I'm using the Firebase Admin SDK in cloud functions to send my notification. My payload is like the following:

{
    "topic": "1289_1352",
    "notification": {
        "body": "Be Member: Hello guys",
        "title": "Be Member"
    },
    "android": {
        "priority": "normal",
        "ttl": 3600,
        "notification": {
            "sound": "default",
            "color": "#0099ff",
            "icon": "fcm_push_icon"
        }
    },
    "apns": {
        "payload": {
            "aps": {
                "badge": 1,
                "sound": "default"
            }
        }
    },
    "data": {
        "ownerName": "Be Member",
        "ownerPicture": "https://be-api-production.s3.eu-central-1.amazonaws.com/production/upload/user_image_upload/99557/upload",
        "chatMessage": "Hello guys",
        "type": "new_message",
        "channelId": "1289_1352",
        "messageId": "M6f4bR9x7m0VCmsK61pL"
    }
}

In my application I received the following in "onMessageReceived" callback

aps: {alert: {title: "Be Member", body: "Be Member: Hello guys"}, badge: 1, sound: "default"}
channelId: "1289_1352"
chatMessage: "Hello guys"
gcm.message_id: "1564425263106447"
google.c.a.e: "1"
messageId: "M6f4bR9x7m0VCmsK61pL"
messageType: "notification"
ownerName: "Be Member"
ownerPicture: "https://be-api-production.s3.eu-central-1.amazonaws.com/production/upload/user_image_upload/99557/upload"
type: "new_message"

When I send the push-notification using a script in your test project, with the following command,

npm run-script send -- --message=notification.json --token="cyue3zCM58o:APA91bGeOiciQhMlcAie--Np35CtYiTtZqtpxKUQyT97ahROTeIK5Q8aBjcCyg_lY2wHA5vyRc1zJumUGIWsp4-aCqM2d7sdI4wd6BrxRO1SbfeMTa7iSAXeTPJiSf1596xE3SqKGNuZ"

My app crashes and i see the following log in my xcode

2019-07-29 15:44:11.947966-0300 My Runcard[2820:858944] didReceiveRemoteNotification: {
    aps =     {
        alert =         {
            body = "Notification with default settings";
            title = "Default Notification";
        };
        badge = 1;
        sound = default;
    };
    "gcm.message_id" = 1564425851513033;
    "google.c.a.e" = 1;
    "key_1" = "Data for key one";
    messageType = notification;
    "notification_foreground" = true;
}

2019-07-29 15:44:11.953574-0300 My Runcard[2820:859023] -[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0xd900dc6a1b315eeb
2019-07-29 15:44:11.954552-0300 My Runcard[2820:859023] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0xd900dc6a1b315eeb'
*** First throw call stack:
(0x1ac65d27c 0x1ab8379f8 0x1ac579ab8 0x1ac662ac4 0x1ac66475c 0x102299634 0x10312b6f0 0x10312cc74 0x103134bf4 0x1031358ec 0x10313f77c 0x1ac27d114 0x1ac27fcd4)
libc++abi.dylib: terminating with uncaught exception of type NSException

Am i doing something wrong? I'm sorry

@metinjakupi
Copy link

What are you using as backend? Either add tap manually and modify it.

@mateusduraes
Copy link
Author

Hi @jakupi1 , I'm using NodeJS (Firebase Cloudfunctions), i can easily add the property tapwith a default value that I don't know yet, but the plugin should change it's value, this is what you mean?

@mateusduraes
Copy link
Author

I've tried to set a default value to property tap, but the plugin doesn't change its value, so, it doesn't solve my problem.

I'll be waiting for @dpa99c suggestions, so I can investigate more.

@mateusduraes
Copy link
Author

@dpa99c It only works when I put the following instruction on line 132 of AppDelegate+FirebasePlugin.m:

[mutableUserInfo setValue:self.applicationInBackground forKey:@"tap"];

So, now, I'm able to receive the property tap as a boolean.

This make any sense?
I can create a PR adding the correct value ("background" | "foreground") if you want.

@dpa99c
Copy link
Owner

dpa99c commented Jul 30, 2019

@mateusduraes just to confirm - in your scenario, is the call to onMessageReceived() triggered by:

  • a notification message arriving while app is in the foreground?
  • tapping a notification while the app is in the foreground?
  • tapping a notification while the app is in the background (but running)?
  • tapping a notification while the app is not running?

@freddysu
Copy link

freddysu commented Jul 30, 2019

I got the similar issue in my project but not in the example project as well.
On Android it works perfectly in both foreground, background and not running.

On iOS, when I set "notification_foreground" to "true",

  • A notification message arriving while app is in the foreground, it crashes.
  • A notification message arriving while app is in the background, I tapped the notification and then the app crashed.
  • When the app is not running, I tapped the notification it won't crash and worked perfectly.

So the next thing I tried is to remove the "notification_foreground" attribute.

On iOS, when I send a notification without the "notification_foreground" attribute, my app won't crash when a notification arriving either in foreground, background or not running.
However, I realised that no "tap" attribute in onMessageReceived callback anymore after I tap the notification when the app is in the background. (But still works perfectly when app is not running)

Thanks for the help!

@dpa99c
Copy link
Owner

dpa99c commented Jul 30, 2019

Reopening as there's obviously some underlying issues here.

One thing I will do is add top-level exception handling for iOS (like I've done for Android) to prevent app crashes.

@mateusduraes With regard to the cause of your crash, I suspect the problem is the sound attribute. In your crashlog I see the sound value is shown as sound = default; i.e. not sound = "default"; and the exception message is [__NSCFNumber isEqualToString:]: unrecognized selector sent to instance so I think that's being raised on this line because it's trying to compare sound as a string but it looks like it's not actually an NSString*. I'll need to investigate why this is.

@freddysu with regard to the tap attribute, it should only be set if the notification is actually tapped - it shouldn't be set when onMessageReceived() is called in response to a notification message actually being received by the app directly from FCM (i.e. notification not tapped by user).

@dpa99c dpa99c reopened this Jul 30, 2019
@freddysu
Copy link

Thanks for the quick reply. Sorry for the incorrect description above. I've edited my comment:)

@mateusduraes
Copy link
Author

mateusduraes commented Jul 30, 2019

@mateusduraes just to confirm - in your scenario, is the call to onMessageReceived() triggered by:

  • a notification message arriving while app is in the foreground? Yes, i receive it
  • tapping a notification while the app is in the foreground? I'm not using the property notification_foreground, but for me, it doesn't work. When i tried to use notification_foreground, i received the notification in onMessageReceived callback, but, the notification toast wasn't showed was expected
  • tapping a notification while the app is in the background (but running)? Yes, i receive it
  • tapping a notification while the app is not running? Yes, i receive it

@shinwenli
Copy link

Although it may be another problem, my ios terminal could not receive system notification at foreground time. ("Notification_foreground" = true)
It was caused by calling "FirebasePlugin.grantPermission".
If you did not call "FirebasePlugin.grantPermission" (after getting the token once and restarting it), you could display the system notification.

The version is "cordova-plugin-firebasex 6.0.2".

@freddysu
Copy link

@shinwenli You are right! Thanks for your feedback.

If I removed the "FirebasePlugin.grantPermission()", it works perfect on iOS.

Now I just call "getPermission" the first time after the app is installed, which means only at the first time when the user opens the app, grant the permission and then if there is a notification arrives will crash the app.

After the user restarts the app, it works perfectly in "foreground", "background" and "not running" even with the "notification_foreground" attribute on iOS.

@syagawa
Copy link

syagawa commented Jul 31, 2019

I had the same problem.
But, solved by "not calling grantPermission".

In my app, call hasPermission then call grantPermission.
I was expecting Object to be an argument of the hasPermission callback, but it was actually boolean.
hasPermission becomes false, and grantPermission has been called.

This problem occurred because I changed the plugin of the app from "cordova-plugin-firebase" to "cordova-plugin-firebasex".

thank you @shinwenli, @dpa99c

@jpduckwo
Copy link

jpduckwo commented Aug 1, 2019

Definitely solved for me by making sure grantPermission was not called unless hasPermission returns false... all worked after that! Thanks

dpa99c pushed a commit that referenced this issue Aug 5, 2019
…turn an error (rather than attempting to grant permission again which causes issues).

See #61
dpa99c pushed a commit that referenced this issue Aug 5, 2019
…ected exceptions in order to prevent app crashes.

Log exceptions to native and JS consoles.
See �#61.
@Lucab95
Copy link

Lucab95 commented Aug 5, 2019

@shinwenli You are right! Thanks for your feedback.

If I removed the "FirebasePlugin.grantPermission()", it works perfect on iOS.

Now I just call "getPermission" the first time after the app is installed, which means only at the first time when the user opens the app, grant the permission and then if there is a notification arrives will crash the app.

After the user restarts the app, it works perfectly in "foreground", "background" and "not running" even with the "notification_foreground" attribute on iOS.

I have the same problem(notifications work only after restarting the app), has the last commit solved the issue?

@dpa99c dpa99c removed the awaiting response If no response, issue will be closed label Aug 6, 2019
@yoldar
Copy link

yoldar commented Aug 6, 2019

Hi @dpa99c, thank you so much for the feedback so quickly.
It worked like a charm in the test project but i still have problems in my project.

I will make some investigations and let you know. I believe you can close the issue for now.

Same problem with my project :(

@dpa99c
Copy link
Owner

dpa99c commented Aug 6, 2019

I've just published v6.0.3 which should address the multiple problems captured in this issue.
Please regression test and let me know if there are still any issues, but I will close this for now as I believe they have all been addressed.

@dpa99c dpa99c closed this as completed Aug 6, 2019
@ghidoz
Copy link

ghidoz commented Aug 16, 2019

Hi, I'm using v6.0.6 and still there is a problem with the tap property on iOS.

Steps to reproduce:

  • Install the app on iPhone the first time
  • Call grantPermission for asking for perms
  • Put the app in background
  • Send a notification
  • Tap on it
  • View the response in console: no tap property

However, if I close the app completely and open it again, since I don't call grantPermission again, I recevie the tap property when tapping on the system notification.

So the problem is still present, when calling grantPermission.

@yoldar
Copy link

yoldar commented Aug 24, 2019

Hi, I'm using v6.0.6 and still there is a problem with the tap property on iOS.

Steps to reproduce:

  • Install the app on iPhone the first time
  • Call grantPermission for asking for perms
  • Put the app in background
  • Send a notification
  • Tap on it
  • View the response in console: no tap property

However, if I close the app completely and open it again, since I don't call grantPermission again, I recevie the tap property when tapping on the system notification.

So the problem is still present, when calling grantPermission.

Same problem

@Yuripetusko
Copy link

Same here, I get tap property only if app is completely closed when clicking on notification

@shinwenli
Copy link

I was able to solve this problem with Version 6.1.0.

Thank you @dpa99c.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ios relates to iOS platform runtime issue An issue related to app runtime
Projects
None yet
Development

No branches or pull requests