Skip to content

ios: Fix unwanted in-app notification sound when phone is on silent.#4898

Merged
chrisbobbe merged 11 commits intozulip:mainfrom
chrisbobbe:pr-ios-notification-sound
Sep 10, 2021
Merged

ios: Fix unwanted in-app notification sound when phone is on silent.#4898
chrisbobbe merged 11 commits intozulip:mainfrom
chrisbobbe:pr-ios-notification-sound

Conversation

@chrisbobbe
Copy link
Copy Markdown
Contributor

(And some follow-up cleanups.)

I've kept my personal iPhone on iOS 13 just in case, and here's a case where that paid off! I was able to test this on my device, and that helped me notice that UNNotificationPresentationOptionBanner (which is iOS 14+) didn't do anything on my device, and that I should include UNNotificationPresentationOptionAlert for iOS <14 support.

A consequence is that I haven't been able to test on iOS 14 yet. I get this output from logging.warn if I try to test on a simulator running iOS 14:

Failed to register iOS push token: 3010

raw_error: {"message":"remote notifications are not supported in the simulator","details":{"NSLocalizedDescription":"remote notifications are not supported in the simulator"},"code":3010}

(Looks like we can only test push notifications on a real device.) Should I upgrade my own device to iOS 14, or does someone with a device running iOS 14 want to test, or do we think it's fine without testing on 14?

Fixes: #4897

@gnprice
Copy link
Copy Markdown
Member

gnprice commented Jul 28, 2021

Thanks!

Testing out this area of behavior (first with just a released version, to understand the status quo), I'm actually kind of puzzled -- I can't seem to reproduce the behavior we expect.

(This is something I don't see in my own normal personal use, because I always have my devices on silent/vibrate for notifications.)

  • On iOS, on an iPhone 7 running 12.4.1 and v27.163 of the app, what I find (after turning off silent mode) on getting a notification for a PM is:

    • When the app isn't running, I get a banner and a sound, the system's default notification sound. This part is expected.
    • Ditto when the app is in the background.
    • When the app is in the foreground, I get neither a banner nor any sound. This is puzzling -- the code that gets deleted at the start of this PR was expected to be playing a sound in this case, right?
  • On iOS, on an iPad mini 4 running iOS 14.6 and v27.166 of the app, what I find (after turning up the volume) is:

    • When the app isn't running, I get the notification as a banner and in Notification Center, and no sound. I don't know why there's no sound.
      • I checked the system's notification settings for the Zulip app, and it's allowed to play sounds.
    • Ditto when the app is in the background.
    • When the app is in the foreground, I get neither a banner (nor anything in Notification Center) nor any sound. This is puzzling but the same as on that iPhone 7.
  • On Android, on a Pixel 4 running Android 11 and v27.166 of the app, what I find (after turning up the "Ring & notification volume", and also all the other volume scales for good measure) is:

    • When the app isn't running, I get the notification in the system notifications UI at the top of the screen, but don't get any sound.
      • I also don't see the notification pop on screen as an alert. This is puzzling because I would definitely have said that I normally do; I don't know if something changed, or what. Digging into the notification settings, I have the "Pop on screen" setting enabled for the Zulip app's notifications.
    • Ditto when it's in the background.
    • Ditto also when it's in the foreground -- in particular, still no sound. This is puzzling for the same reason as on iOS: I would have expected the code that gets deleted at the start of this PR was to be playing a sound in this case.

What behavior do you see, before your changes?

@gnprice
Copy link
Copy Markdown
Member

gnprice commented Jul 28, 2021

All the cleanups that come after the behavior changes look good!

TODO: Probably just do a CommonActions.goBack()?

This sounds pretty reasonable. I wonder how it ends up differing from StackActions.pop(), which would be the most direct simplification of what we currently have. In particular, if you happen to indeed be in a stack navigator, does it always do the same thing?

@chrisbobbe
Copy link
Copy Markdown
Contributor Author

chrisbobbe commented Jul 28, 2021

I can't seem to reproduce the behavior we expect

Hmm! Interesting. For the problem where you expect to hear a sound while foregrounded, before these changes:

This may have been implicit, but did you read through the code in doEventActionSideEffects and decide that you were pretty sure that playMessageSound would have been called in the released app? I think you could also check this with some logging in a debug build, without having to set up push notifications (since the playMessageSound call has nothing to do with push-notification code).

I've just tried on my iPhone, and I'm hearing our "thump" sound when I get a PM from another account and I don't have any message lists open.

Edit: I've also just tried on the office Android device, and I'm getting a visible notification and an Android notification sound, along with the "thump" sound.

@chrisbobbe
Copy link
Copy Markdown
Contributor Author

I can't seem to reproduce the behavior we expect

It looks like this was resolved, and you managed to reproduce it: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/notification.20sound.20bug/near/1240401

@chrisbobbe chrisbobbe force-pushed the pr-ios-notification-sound branch from 27d4c08 to d9cf445 Compare July 29, 2021 16:15
@chrisbobbe
Copy link
Copy Markdown
Contributor Author

chrisbobbe commented Jul 29, 2021

I wonder how it ends up differing from StackActions.pop(), which would be the most direct simplification of what we currently have.

Good point—I've just pushed a revision that says StackActions.pop() in that comment; we should go for the most direct simplification, at least for now.

On iOS, for zulip#4897, we instead want to use the native
notification-sound functionality. So, do that, by adding a line to
AppDelegate.m.

We should still carve out an exception: we won't need to notify the
user if the relevant item (a new or updated message) is already on
the user's screen. Doing so could be annoying; for example, you
don't need to be notified about every single message in an active PM
conversation. That's issue zulip#3114, and it'll take some work. But this
change improves the behavior on iOS and it matches the existing
behavior on Android.

On Android, this JS function call has apparently been duplicating
the notification sound that gets played at a lower level, so it's
fine for Android to remove this.

Fixes: zulip#4897
A sound, by itself, would tell the user that something interesting
happened, but without giving them a clue about what the interesting
thing was. So, use a banner for that.

We should still eventually not show these for messages that already
appear on the screen, as we mentioned for notification sounds in the
previous commit.
Along with the one bit of now-unused code (as of this series) that
was importing it.
This was a lot of setup for the in-app "notification" sound, which
we removed in a recent commit.
…pers.

navSelectors and navActions are kind of relics from before zulip#3804,
and we already have zulip#4417 for removing most or all of navActions.

Help along the removal of navSelectors by removing these things that
we stopped using in a recent commit.
As mentioned in a previous commit, navSelectors and navActions are
kind of relics from before zulip#3804, and we already have zulip#4417 for
removing most or all of navActions.

Might as well remove navSelectors.
@chrisbobbe chrisbobbe force-pushed the pr-ios-notification-sound branch from d9cf445 to a19eb69 Compare September 10, 2021 20:30
@gnprice
Copy link
Copy Markdown
Member

gnprice commented Sep 10, 2021

This code looks good! And we've just tested on iOS 14 (on my iPhone 7, which I upgraded yesterday from iOS 12), and it works as intended.

Please merge at will. I believe you're in the middle of testing again on iOS 13.

@chrisbobbe
Copy link
Copy Markdown
Contributor Author

I believe you're in the middle of testing again on iOS 13.

Yep, this worked as expected. Yay!

@chrisbobbe chrisbobbe merged commit a19eb69 into zulip:main Sep 10, 2021
@chrisbobbe
Copy link
Copy Markdown
Contributor Author

Thanks for the review! Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ios: Unwanted in-app notification sound when phone is on silent.

2 participants