Page MenuHomePhabricator

Create demo iOS client for Push Notifications
Closed, ResolvedPublic

Description

Background information

During the development of the new push-notifications infrastructure, the PI engineers would like to have a simple demo client to test the infrastructure before the integration with the main Wikipedia app begins.

What

  • A demo iOS app with very simple functionality that can subscribe to the push service and receive push-notifications.

How

...

Open questions

  • How to display the received content, e. g. raw vs pretty format or both?

Acceptance criteria

  • The app is able to subscribe to the push-service
  • The app can receive push-notifications
  • The app is able to display the received content as descriptive as possible

Event Timeline

I built a minimal website to work on push notifications on Safari (so we don't need a device for the API service development).
Currently its deployed on toolforge as a static page [1] backed by [2] to register the push package as documented in the Apple documentation [3]

This is using my personal certs at the moment but it would be great if we can issue certs from the WMF developer account.

@JoeWalsh I verified that I have access to developer.apple.com with my WMF email and I can issue certs but I don't have the rights to create the identifier for Website Push IDs.
Also under certs I can only generate certs under Software but not under Services > Website Push ID. Can you help me with that?

[1] https://tools-static.wmflabs.org/push-notifications-helper/
[2] https://push-notifications-helper.toolforge.org
[3] https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/NotificationProgrammingGuideForWebsites/PushNotifications/PushNotifications.html

@Jgiannelos I crated web push IDs for a few different domains (don't know if you need them all, or even if you need different ones for different domains, feel free to use whichever are relevant). Are you able to create the certs for those newly created IDs?

I can see the new Push IDs but I am still not allowed to generate certificates (clicking the button directly is disabled, and web push cert doesn't show up as an option under create new certificate)

I updated your permissions, let me know if you have access now

I managed to issue the certificate. Thanks @JoeWalsh for helping sorting this out!

@JoeWalsh Just curious, were the PI folks here added to WMF's Apple Developer Team License?

@dcipoletti yes, they were added as users to the WMF Apple Developer / App Store Connect account

Wanted to provide a quick update on this – I'm pretty close to completing a first pass of an iOS demo client with the acceptance criteria mentioned in the description. Part of my research and prototyping involved confirming that when we eventually bring this work into the Wikipedia client app that we'll be able to have the behavioral characteristics we're looking for.

Here's that iOS client: https://github.com/wikimedia/notifications-utility-ios. Let me know if anyone else needs admin access on it.

Hopefully the README is helpful, but don't hesitate to let me know if there are any questions or anything I can do to improve it for your purposes. Also wanted to mention again, if it's useful, I can figure out how to set up TestFlight for effortless distribution and deployment to your test devices (much easier than the annoying requirements for Xcode, Apple Developer access, etc. for manual device deployment).

Hey @Dmantena, thanks for working on this! On this (semi-)silent Friday I finally got a chance to take a look. I got it up and running in Xcode and was able to receive a device token without any trouble. However, I don't seem to be receiving any notifications on my device, even though the APNS server (api.development.push.apple.com) is responding with a 200 status. I tried setting some debug breakpoints in NotificationService.swift to see if messages were being received by the app but discarded for some reason, but that doesn't seem to be the case, either.

Here's an example of the notification request body being sent from the push-notifications service (with a small local change not yet on master to set mutable-content):

{
  "data": {
    "type":"checkEchoV1"
  },
  "aps":{
    "thread-id":"checkEchoV1",
    "mutable-content":1
  }
}

From the docs, it looks like a message can contain arbitrary top-level keys alongside aps, so it doesn't seem like APNS should be rejecting the message as malformed because of the data key. Maybe there's some required key(s) in the aps object itself that we're missing? I don't see anything in the docs to indicate that, though.

It's possible the trouble is just that I have really terrible cellular signal (usually actually no signal) in the house, but going outside to get a better cell connection doesn't seem to help.

On a side note, when I use the production rather than the development server, the request fails with {"reason": "BadDeviceToken"}, but I'm guessing the credentials we're using are scoped to development only, and that's expected behavior?

@Mholloway To recap from the meeting this morning and follow-up based on testing:

  1. To have the notifications be logged and shown in the demo app, you must add a value for the "alert" key in the APS dictionary. Otherwise, the notification will effectively just be ignored by the app (and won't wake the user's device).

So altering your payload here to:

{
  "data": {
    "type":"checkEchoV1"
  },
  "aps":{
    "thread-id":"checkEchoV1",
    "mutable-content":1,
    "alert": "Echo Hello"
  }
}

should result in a. the NotificationService.swift paths being hit b. the notification with payload being logged in the client itself and c. the alert banner showing up on device.

  1. When deploying from Xcode to device, the app is automatically provisioned with entitlements to Apple's development/sandbox push environment. When downloaded by a user in the App Store or on TestFlight, the app is provisioned with entitlements to Apple's production push environment. This is not developer configurable. Device tokens are unique to the respective Apple push environment, so in your example here, using a development environment device token (built from Xcode and deployed to device) in the production environment results in bad device token error – Apple's production environment has no knowledge of that development environment specific device token.

I've went ahead and updated the repo README with these details as well. Again, don't hesitate to let me know if you're having any trouble getting up and running or if there's anything related I can help unblock.

Thanks, @Dmantena! By locally updating the service code to pass in an alert field, I was able to verify receipt of a message on my local build. I think we can call this resolved.

Hey @Dmantena, sorry to revive this, but would it be much trouble to set this up for internal testing in TestFlight after all? I just tried to do it myself but I don't see it in the apps list for the org account in App Store Connect.

I got a new phone a month or so ago and would rather go the TestFlight route if possible rather than setting it up as a dev device and all that.

@Mholloway For sure – I'm happy to set up TestFlight for this to ease the process of using it. Just so you're aware of timeline, we've got a big release coming out later this morning that will require some focus, and after I set up the App Store Connect profile for the utility and enable TestFlight testing, Apple has to approve it for external testing (for our internal team.) Usually it's pretty quick, but with iOS 14 coming out today it's an unknown how long it'll take. But I will at least get this process started today.

Thanks, @Dmantena. I'd say as long as we're able to run through the basic workflow by, say, Friday, that's fine. Good luck with today's release!

@Dmantena Actually, I got this working again on the old phone, so if you haven't started yet, probably not worth the trouble. Sorry about that!

@Mholloway Glad you got it working. I've already done most of the heavy lifting, so I'm going to finish it out. Hopefully it will allow other folks on the team that aren't set up with an Apple Developer account and Xcode to more easily test on device.

@Mholloway Apple approved the client for TestFlight beta testing over the weekend. So don't hesitate to let me know if you'd like me to add anyone with an iOS device to use it (they don't need Xcode or to be a registered Apple developer or any other special credentials). I can create a "public" link for installing it or you can just pass some email addresses to me and I can add them manually.

Hi @Dmantena! Thanks for the testflight release, can you share a link with me?

@Jgiannelos Sure thing - invite just sent

Thanks very much @Dmantena! The TestFlight release was already very useful for testing the production deployment to testwiki yesterday.