Skip to content

Support push for Live Activity - #668

Merged
jonathanedey merged 3 commits into
firebase:devfrom
morikuni:dev
Jun 3, 2025
Merged

Support push for Live Activity#668
jonathanedey merged 3 commits into
firebase:devfrom
morikuni:dev

Conversation

@morikuni

Copy link
Copy Markdown
Contributor

@xiaolongbao321

Copy link
Copy Markdown

hi bro

when the feature can be used?
i use the code in local. sending to firebase is successful, but the ios app no response.
show me the code.
can you help me to change?

Thanks!

package main

import (
	"context"
	firebase "firebase.google.com/go/v4"
	"firebase.google.com/go/v4/messaging"
	"fmt"
	"google.golang.org/api/option"
	"log"
	"os"
	"time"
)

func main() {
	println(os.Getwd())
	// 使用下载的服务账户密钥文件路径
	opt := option.WithCredentialsFile("./mePlus/to_firebase_ios/serviceAccountKey.json")
	app, err := firebase.NewApp(context.Background(), nil, opt)
	if err != nil {
		log.Fatalf("error initializing app: %v\n", err)
	}

	ctx := context.Background()
	client, err := app.Messaging(ctx)
	if err != nil {
		log.Fatalf("error getting Messaging client: %v\n", err)
	}
	now := time.Now()
	unixTime := time.Unix(1546304, 0)
	fcmOptions := new(messaging.APNSFCMOptions)
	fcmOptions.AnalyticsLabel = "test-live-activity"
	message := &messaging.Message{
		APNS: &messaging.APNSConfig{
			Headers: map[string]string{
				"apns-priority": "10",
				//"apns-topic":     "", // 必须添加的实时活动主题头
				"apns-push-type": "liveactivity", // 标识为实时活动推送
			},
			Payload: &messaging.APNSPayload{
				Aps: &messaging.Aps{
					Alert: &messaging.ApsAlert{
						Title: "123",
						Body:  "123",
					},
					//Sound:          "default",
					StaleDate:      &unixTime,
					Event:          messaging.LiveActivityEventStart,
					Attributes:     map[string]interface{}{},
					AttributesType: "MissedEnergy",
					ContentState:   map[string]interface{}{},
					DismissalDate:  &unixTime,
					Timestamp:      &now,
				},
			},
			FCMOptions:        fcmOptions,
			LiveActivityToken: "80a8a14077cc0e4392fbb5f4ae7bb329dbf0af5b8b384c5d1baba0a78b3227be3dbeba200dbfa150b8705f9364b0f5204d92267d82c093315911f9c9ed35be76a0c004c140c340d18644b2b7a513fd09",
		},
		Token: "dJ1H2SMWU0Q4lC6TI6_lED:APA91bGStzxLSXcpbPtwE_S8PcfOZt6Ob-BMAetQaenKa0WRtA6G731E1kAhzIjH4NvZsE1_37KYZmv-hBNWWg_F02Bwpc1rKopBhti1cOw_dGer8WHOLfg",
	}

	// 发送消息
	response, err := client.Send(ctx, message)
	if err != nil {
		log.Fatalf("error sending message: %v\n", err)
	}

	// 打印响应
	fmt.Printf("成功发送消息: %s\n", response)
}

@djain176

djain176 commented May 2, 2025

Copy link
Copy Markdown

HI Guys,
Please let us know when this pr will be merged, we also have dependency on this.
If possible then can we prioritised this pr

@lahirumaramba
lahirumaramba self-requested a review May 12, 2025 20:23
@lahirumaramba lahirumaramba self-assigned this May 12, 2025
@osamingo

Copy link
Copy Markdown

@lahirumaramba Hi, I have a request regarding for code review of this 👀

The live_activity_token has to be defined in the same layer as the headers.
Therefore, using the current SDK, it's not possible to update LiveActivity remotely from the backend side. (the other hand, the payload can be resolved by using CustomData )

Please, code review if possible would be greatly appreciated 🙋🏼

@jonathanedey
jonathanedey self-requested a review May 27, 2025 19:59

@jonathanedey jonathanedey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @morikuni, Thanks for getting started on this. Could you remove the extra fields added and limit to just LiveActivityToken field. Thanks!

Comment thread messaging/messaging.go Outdated
As per review feedback, removed all extra Live Activity fields from Aps struct:
- Removed StaleDate, ContentState, Timestamp, Event, DismissalDate, AttributesType, and Attributes fields
- Removed LiveActivityEvent type and constants
- Updated tests to only test LiveActivityToken field
- Kept only the essential LiveActivityToken field in APNSConfig as requested
@morikuni

morikuni commented Jun 3, 2025

Copy link
Copy Markdown
Contributor Author

@jonathanedey I’ve removed all the extra fields and now only include the LiveActivityToken. Could you review it again?

@morikuni
morikuni requested a review from jonathanedey June 3, 2025 00:27
@jonathanedey
jonathanedey requested review from chong-shao and removed request for lahirumaramba June 3, 2025 13:39
@jonathanedey

Copy link
Copy Markdown
Contributor

Thanks again @morikuni for the contribution!

@jonathanedey
jonathanedey merged commit df85e6c into firebase:dev Jun 3, 2025
@jonathanedey jonathanedey linked an issue Jun 5, 2025 that may be closed by this pull request
@Mickey0811

Copy link
Copy Markdown

As per review feedback, removed all extra Live Activity fields from Aps struct:

  • Removed StaleDate, ContentState, Timestamp, Event, DismissalDate, AttributesType, and Attributes fields
  • Removed LiveActivityEvent type and constants
  • Updated tests to only test LiveActivityToken field
  • Kept only the essential LiveActivityToken field in APNSConfig as requested

Why was this change reverted? How can I pass fields like Event and ContentState through an HTTP request

Or how should I construct the request parameters for LiveActivity? I see that currently there is only a type APNSPayload
struct {
Aps *Aps json:"aps,omitempty"
CustomData map[string]interface{} json:"-"
}
It seems that this struct cannot pass the aforementioned parameters out

@morikuni @jonathanedey

@Mickey0811

Copy link
Copy Markdown

Has your issue been resolved? After sending the liveActivity request, does the iOS app respond

@xiaotuotuo321

@jonathanedey

Copy link
Copy Markdown
Contributor

Hi @Mickey0811,

These fields can be set using the Aps struct's CustomData field:

&messaging.Message{
	Token: "test-token",
	APNS: &messaging.APNSConfig{
		LiveActivityToken: "live-activity-token",
		Payload: &messaging.APNSPayload{
			Aps: &messaging.Aps{
				CustomData: map[string]interface{}{
					"event": "start",
					"content-state": map[string]interface{}{
						"demo": 1,
					},
				},
			},
		},
	},
},

If that's not what you're seeing, could you please open a new issue and include as many details as you can (or even a minimal repro) so we can take look.

@firebase firebase locked as resolved and limited conversation to collaborators Aug 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

how to send ios live activity

9 participants