mentionapp / apns.go

Client library for the Apple Push Notification Service (APNS), focusing on reliability
Other
5 stars 1 forks source link

Refactoring #1

Closed gronpipmaster closed 9 years ago

arnaud-lb commented 9 years ago

Thanks!

arnaud-lb commented 9 years ago

@gronpipmaster the change is not backwards-compatible, as Notification.Payload() now returns a Topic (it used to return a *Payload). Any chance of making this backwards-compatible?

gronpipmaster commented 9 years ago

Yes you are right, but I believe that the use of:

payload := notif.Payload().(*apns.Payload)

Is bad idea. Custom type custing, reflection, and other.

New usage:

payload := new(apns.Payload)
payload.SetAlertString("Alert")
notif.SetPayload(payload)

//or create me type support method Bytes
type MyPayload struct {
    foo []byte
}

func(m MyPayload) Bytes() ([]byte, error){
    return m.foo, nil
}

payload := &MyPayload{foo:[]byte(`{"aps":{"alert":"Alert 111!","badge":1}}`)}
notif.SetPayload(payload)

This small backwards-compatible change allows a more versatile use.