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

Way to unmarshal Message from json string (apns.payload.aps.*) #590

Open
jeyraof opened this issue Oct 18, 2023 · 0 comments
Open

Way to unmarshal Message from json string (apns.payload.aps.*) #590

jeyraof opened this issue Oct 18, 2023 · 0 comments

Comments

@jeyraof
Copy link

jeyraof commented Oct 18, 2023

[REQUIRED] Step 2: Describe your environment

  • Operating System version: macOS Ventura 13.5.2
  • Firebase SDK version: 4.12.1
  • Library version: ?
  • Firebase Product: messaging (auth, database, storage, etc)

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

I've deal with json like:

{
  "token": "$FCM_TOKEN",
  "data": {
    "title": "data.title",
    "body": "data.body"
  },
  "notification": {
    "title": "notification.title",
    "body": "notification.body"
  },
  "apns": {
    "payload": {
      "aps": {
        "content-available": false,
        "sound": "1",
        "mutable-content": true,
        "alert": {
          "title": "apns.payload.aps.alert.title",
          "subtitle": "apns.payload.aps.alert.subtitle",
          "body": "apns.payload.aps.alert.body"
        }
      }
    }
  }
}

For use Message's interface, I have to unmarshal this json to Message struct.
So I tried to:

// 1st way
message := &messaging.Message{}
err = message.UnmarshalJSON(messageJsonString)
if err != nil {
	fmt.Println(err.Error())
}

// 1st way's error:
json: cannot unmarshal bool into Go struct field APNSConfig.apns.payload of type int
// 2nd way
message := &messaging.Message{}
err = json.Unmarshal(messageJsonString)
if err != nil {
	fmt.Println(err.Error())
}

// 2nd way's error:
json: cannot unmarshal bool into Go struct field APNSConfig.apns.payload of type int

I did some testing and found that it works fine without "content-available" and "mutable-content" in the json.
How can I parse content-available and mutable-content?
This fields are from apple reference

@jeyraof jeyraof changed the title Way to unmarshal Message from json string. Way to unmarshal Message from json string (apns.payload.aps.*) Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants