-
Notifications
You must be signed in to change notification settings - Fork 268
Support push for Live Activity #668
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
Conversation
|
hi bro when the feature can be used? 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)
} |
|
HI Guys, |
|
@lahirumaramba Hi, I have a request regarding for code review of this 👀 The Please, code review if possible would be greatly appreciated 🙋🏼 |
There was a problem hiding this comment.
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!
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
|
@jonathanedey I’ve removed all the extra fields and now only include the LiveActivityToken. Could you review it again? |
|
Thanks again @morikuni for the contribution! |
|
As per review feedback, removed all extra Live Activity fields from Aps struct:
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 |
|
Has your issue been resolved? After sending the liveActivity request, does the iOS app respond |
|
Hi @Mickey0811, These fields can be set using the &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. |
Added keys for Live Activity push.
Firebase Document: https://firebase.google.com/docs/cloud-messaging/ios/live-activity
Firebase API Reference: https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#apnsconfig
APNS Reference: https://developer.apple.com/documentation/usernotifications/generating-a-remote-notification