Skip to content

Commit c0c7ebb

Browse files
authored
Add location push type (sideshow#194)
* Add location push type * Fix Typo * Add InvalidPushType reason error code
1 parent bf64dd4 commit c0c7ebb

File tree

4 files changed

+49
-24
lines changed

4 files changed

+49
-24
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ APNS/2 is a go package designed for simple, flexible and fast Apple Push Notific
1111
- Works with go 1.7 and later
1212
- Supports new Apple Token Based Authentication (JWT)
1313
- Supports new iOS 10 features such as Collapse IDs, Subtitles and Mutable Notifications
14-
- Supports new iOS 15 fetaures interruptionLevel and relevanceScore
14+
- Supports new iOS 15 features interruptionLevel and relevanceScore
1515
- Supports persistent connections to APNs
1616
- Supports VoIP/PushKit notifications (iOS 8 and later)
1717
- Modular & easy to use

client_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,17 @@ func TestPushTypeBackgroundHeader(t *testing.T) {
252252
assert.NoError(t, err)
253253
}
254254

255+
func TestPushTypeLocationHeader(t *testing.T) {
256+
n := mockNotification()
257+
n.PushType = apns.PushTypeLocation
258+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
259+
assert.Equal(t, "location", r.Header.Get("apns-push-type"))
260+
}))
261+
defer server.Close()
262+
_, err := mockClient(server.URL).Push(n)
263+
assert.NoError(t, err)
264+
}
265+
255266
func TestPushTypeVOIPHeader(t *testing.T) {
256267
n := mockNotification()
257268
n.PushType = apns.PushTypeVOIP

notification.go

+32-21
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,52 @@ type EPushType string
1111
const (
1212
// PushTypeAlert is used for notifications that trigger a user interaction —
1313
// for example, an alert, badge, or sound. If you set this push type, the
14-
// apns-topic header field must use your app’s bundle ID as the topic. The
15-
// alert push type is required on watchOS 6 and later. It is recommended on
16-
// macOS, iOS, tvOS, and iPadOS.
14+
// topic field must use your app’s bundle ID as the topic. If the
15+
// notification requires immediate action from the user, set notification
16+
// priority to 10; otherwise use 5. The alert push type is required on
17+
// watchOS 6 and later. It is recommended on macOS, iOS, tvOS, and iPadOS.
1718
PushTypeAlert EPushType = "alert"
1819

1920
// PushTypeBackground is used for notifications that deliver content in the
2021
// background, and don’t trigger any user interactions. If you set this push
21-
// type, the apns-topic header field must use your app’s bundle ID as the
22-
// topic. The background push type is required on watchOS 6 and later. It is
23-
// recommended on macOS, iOS, tvOS, and iPadOS.
22+
// type, the topic field must use your app’s bundle ID as the topic. Always
23+
// use priority 5. Using priority 10 is an error. The background push type
24+
// is required on watchOS 6 and later. It is recommended on macOS, iOS,
25+
// tvOS, and iPadOS.
2426
PushTypeBackground EPushType = "background"
2527

28+
// PushTypeLocation is used for notifications that request a user’s
29+
// location. If you set this push type, the topic field must use your app’s
30+
// bundle ID with .location-query appended to the end. The location push
31+
// type is recommended for iOS and iPadOS. It isn’t available on macOS,
32+
// tvOS, and watchOS. If the location query requires an immediate response
33+
// from the Location Push Service Extension, set notification apns-priority
34+
// to 10; otherwise, use 5. The location push type supports only token-based
35+
// authentication.
36+
PushTypeLocation EPushType = "location"
37+
2638
// PushTypeVOIP is used for notifications that provide information about an
27-
// incoming Voice-over-IP (VoIP) call. If you set this push type, the
28-
// apns-topic header field must use your app’s bundle ID with .voip appended
29-
// to the end. If you’re using certificate-based authentication, you must
30-
// also register the certificate for VoIP services. The voip push type is
31-
// not available on watchOS. It is recommended on macOS, iOS, tvOS, and
32-
// iPadOS.
39+
// incoming Voice-over-IP (VoIP) call. If you set this push type, the topic
40+
// field must use your app’s bundle ID with .voip appended to the end. If
41+
// you’re using certificate-based authentication, you must also register the
42+
// certificate for VoIP services. The voip push type is not available on
43+
// watchOS. It is recommended on macOS, iOS, tvOS, and iPadOS.
3344
PushTypeVOIP EPushType = "voip"
3445

3546
// PushTypeComplication is used for notifications that contain update
3647
// information for a watchOS app’s complications. If you set this push type,
37-
// the apns-topic header field must use your app’s bundle ID with
38-
// .complication appended to the end. If you’re using certificate-based
39-
// authentication, you must also register the certificate for WatchKit
40-
// services. The complication push type is recommended for watchOS and iOS.
41-
// It is not available on macOS, tvOS, and iPadOS.
48+
// the topic field must use your app’s bundle ID with .complication appended
49+
// to the end. If you’re using certificate-based authentication, you must
50+
// also register the certificate for WatchKit services. The complication
51+
// push type is recommended for watchOS and iOS. It is not available on
52+
// macOS, tvOS, and iPadOS.
4253
PushTypeComplication EPushType = "complication"
4354

4455
// PushTypeFileProvider is used to signal changes to a File Provider
45-
// extension. If you set this push type, the apns-topic header field must
46-
// use your app’s bundle ID with .pushkit.fileprovider appended to the end.
47-
// The fileprovider push type is not available on watchOS. It is recommended
48-
// on macOS, iOS, tvOS, and iPadOS.
56+
// extension. If you set this push type, the topic field must use your app’s
57+
// bundle ID with .pushkit.fileprovider appended to the end. The
58+
// fileprovider push type is not available on watchOS. It is recommended on
59+
// macOS, iOS, tvOS, and iPadOS.
4960
PushTypeFileProvider EPushType = "fileprovider"
5061

5162
// PushTypeMDM is used for notifications that tell managed devices to

response.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
// StatusSent is a 200 response.
1010
const StatusSent = http.StatusOK
1111

12-
// The possible Reason error codes returned from APNs.
13-
// From table 8-6 in the Apple Local and Remote Notification Programming Guide.
12+
// The possible Reason error codes returned from APNs. From table 4 in the
13+
// Handling Notification Responses from APNs article
1414
const (
1515
// 400 The collapse identifier exceeds the maximum allowed size
1616
ReasonBadCollapseID = "BadCollapseId"
@@ -40,6 +40,9 @@ const (
4040
// 400 Idle time out.
4141
ReasonIdleTimeout = "IdleTimeout"
4242

43+
// 400 The apns-push-type value is invalid.
44+
ReasonInvalidPushType = "InvalidPushType"
45+
4346
// 400 The device token is not specified in the request :path. Verify that the
4447
// :path header contains the device token.
4548
ReasonMissingDeviceToken = "MissingDeviceToken"

0 commit comments

Comments
 (0)