Skip to content

Sending localized push notifications to iOS doesn't work #639

@angeria

Description

@angeria

Environment

  • Operating System version: macOS Mojave 10.14.6
  • Firebase SDK version: 8.4.0
  • Firebase Product: Cloud Messaging
  • Node.js version: 12.6.0
  • NPM version: 6.9.0

Problem

It's not possible to send localized push notifications to iOS in an apns payload. There's an error about incorrect types. I've also tried with body_loc_key and title_loc_key but with same error. The only way to silence the error is to include either title or body in the alert, but that overrides any localization and displays the title/body instead.

Steps to reproduce:

async function sendLocationLostNotification(notificationToken: string, newOwner: string, locationName: string) {
    const message = {
        name: "Location Lost Notification",
        token: notificationToken,
        apns: {
            payload: {
                aps: {
                    alert: {
                        loc_key: "location-lost-notification-body",
                        loc_args: [newOwner, locationName]

                    },
                    sound: "default"
                }
            }
        }
    };

    return await admin.messaging().send(message)
}

Relevant Code:

src/index.ts:109:41 - error TS2345: Argument of type '{ name: string; token: string; apns: { payload: { aps: { alert: { loc_key: string; loc_args: string[]; }; sound: string; }; }; }; }' is not assignable to parameter of type 'Message'.
  Type '{ name: string; token: string; apns: { payload: { aps: { alert: { loc_key: string; loc_args: string[]; }; sound: string; }; }; }; }' is not assignable to type 'TokenMessage'.
    Types of property 'apns' are incompatible.
      Type '{ payload: { aps: { alert: { loc_key: string; loc_args: string[]; }; sound: string; }; }; }' is not assignable to type 'ApnsConfig'.
        Types of property 'payload' are incompatible.
          Type '{ aps: { alert: { loc_key: string; loc_args: string[]; }; sound: string; }; }' is not assignable to type 'ApnsPayload'.
            Types of property 'aps' are incompatible.
              Type '{ alert: { loc_key: string; loc_args: string[]; }; sound: string; }' is not assignable to type 'Aps'.
                Types of property 'alert' are incompatible.
                  Type '{ loc_key: string; loc_args: string[]; }' is not assignable to type 'string | ApsAlert | undefined'.
                    Type '{ loc_key: string; loc_args: string[]; }' has no properties in common with type 'ApsAlert'.

109     return await admin.messaging().send(message)

My SO question.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions