Skip to content

Commit 9e62203

Browse files
Add APNSItemPushType (the apns-push-typewith header field has six valid values)
1 parent 99b2b7b commit 9e62203

File tree

2 files changed

+129
-0
lines changed

2 files changed

+129
-0
lines changed

Knuff/APNSItem.h

+73
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#import "MTLModel.h"
1010

11+
NS_ASSUME_NONNULL_BEGIN
12+
1113
typedef NS_ENUM(NSUInteger, APNSItemMode) {
1214
APNSItemModeCustom,
1315
APNSItemModeKnuff
@@ -18,12 +20,83 @@ typedef NS_ENUM(NSUInteger, APNSItemPriority) {
1820
APNSItemPriorityImmediately = 10
1921
};
2022

23+
typedef NS_ENUM(NSUInteger, APNSItemPushType) {
24+
25+
/**
26+
Use the alert push type for notifications that trigger a user interaction—for example, an alert, badge, or sound. If you set this push type, the apns-topic header field must use your app’s bundle ID as the topic. For more information, see Generating a Remote Notification.
27+
The alert push type is required on watchOS 6 and later. It is recommended on macOS, iOS, tvOS, and iPadOS.
28+
*/
29+
APNSItemPushTypeAlert,
30+
31+
/**
32+
Use the background push type for notifications that deliver content in the background, and don’t trigger any user interactions. If you set this push type, the apns-topic header field must use your app’s bundle ID as the topic. For more information, see Pushing Background Updates to Your App.
33+
The background push type is required on watchOS 6 and later. It is recommended on macOS, iOS, tvOS, and iPadOS.
34+
*/
35+
APNSItemPushTypeBackground,
36+
37+
/**
38+
Use the voip push type for notifications that provide information about an incoming Voice-over-IP (VoIP) call. For more information, see Responding to VoIP Notifications from PushKit.
39+
If you set this push type, the apns-topic header field must use your app’s bundle ID with .voip appended to the end. If you’re using certificate-based authentication, you must also register the certificate for VoIP services. The topic is then part of the 1.2.840.113635.100.6.3.4 or 1.2.840.113635.100.6.3.6 extension.
40+
The voip push type is not available on watchOS. It is recommended on macOS, iOS, tvOS, and iPadOS.
41+
*/
42+
APNSItemPushTypeVoip,
43+
44+
/**
45+
Use the complication push type for notifications that contain update information for a watchOS app’s complications. For more information, see Updating Your Timeline.
46+
If you set this push type, the apns-topic header field must use your app’s bundle ID with .complication appended to the end. If you’re using certificate-based authentication, you must also register the certificate for WatchKit services. The topic is then part of the 1.2.840.113635.100.6.3.6 extension.
47+
The complication push type is recommended for watchOS and iOS. It is not available on macOS, tvOS, and iPadOS.
48+
*/
49+
APNSItemPushTypeComplication,
50+
51+
/**
52+
Use the fileprovider push type to signal changes to a File Provider extension. If you set this push type, the apns-topic header field must use your app’s bundle ID with .pushkit.fileprovider appended to the end. For more information, see Using Push Notifications to Signal Changes.
53+
The fileprovider push type is not available on watchOS. It is recommended on macOS, iOS, tvOS, and iPadOS.
54+
*/
55+
APNSItemPushTypeFileProvider,
56+
57+
/**
58+
Use the mdm push type for notifications that tell managed devices to contact the MDM server. If you set this push type, you must use the topic from the UID attribute in the subject of your MDM push certificate. For more information, see Device Management.
59+
The mdm push type is not available on watchOS. It is recommended on macOS, iOS, tvOS, and iPadOS.
60+
*/
61+
APNSItemPushTypeMDM
62+
};
63+
64+
/**
65+
Default APNSItemPushType.
66+
*/
67+
APNSItemPushType APNSItemPushTypeDefault(void);
68+
69+
/**
70+
Retrieve the valid string value for the HTTP header.
71+
*/
72+
NSString *APNSItemPushTypeToStr(APNSItemPushType pushType);
73+
74+
/**
75+
Retrieve APNSItemPushType from string value.
76+
*/
77+
APNSItemPushType APNSItemPushTypeFromStr(NSString *pushTypeStr);
78+
79+
/**
80+
Retrieve all APNSItemPushType values.
81+
*/
82+
NSArray<NSString *> *APNSItemPushTypesAll(void);
83+
2184
@interface APNSItem : MTLModel
85+
2286
@property (nonatomic, copy) NSString *token;
2387
@property (nonatomic, copy) NSString *payload;
2488
@property (nonatomic) APNSItemMode mode;
2589
@property (nonatomic, copy) NSString *certificateDescription;
2690
@property (nonatomic) APNSItemPriority priority;
91+
92+
/**
93+
Required for watchOS 6 and later; recommended for macOS, iOS, tvOS, and iPadOS) The value of this header must accurately reflect the contents of your notification’s payload. If there is a mismatch, or if the header is missing on required systems, APNs may return an error, delay the delivery of the notification, or drop it altogether.
94+
*/
95+
@property (nonatomic) APNSItemPushType pushType NS_AVAILABLE(10_15, 13_0);
96+
2797
@property (nonatomic) NSString *collapseID;
2898
@property (nonatomic) BOOL sandbox; // Only used when an identity includes both development and production
99+
29100
@end
101+
102+
NS_ASSUME_NONNULL_END

Knuff/APNSItem.m

+56
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,59 @@
1010

1111
@implementation APNSItem
1212
@end
13+
14+
APNSItemPushType APNSItemPushTypeDefault(void) {
15+
return APNSItemPushTypeAlert;
16+
}
17+
18+
NSString *APNSItemPushTypeToStr(APNSItemPushType pushType) {
19+
switch (pushType) {
20+
case APNSItemPushTypeAlert:
21+
return @"alert"; //0
22+
case APNSItemPushTypeBackground:
23+
return @"background"; //1
24+
case APNSItemPushTypeVoip:
25+
return @"voip"; //2
26+
case APNSItemPushTypeComplication:
27+
return @"complication"; //3
28+
case APNSItemPushTypeFileProvider:
29+
return @"fileprovider"; //4
30+
case APNSItemPushTypeMDM:
31+
return @"mdm"; //5
32+
}
33+
}
34+
35+
APNSItemPushType APNSItemPushTypeFromStr(NSString *pushTypeStr) {
36+
if ([pushTypeStr isEqualToString:APNSItemPushTypeToStr(APNSItemPushTypeAlert)]) {
37+
return APNSItemPushTypeAlert;
38+
}
39+
else if ([pushTypeStr isEqualToString:APNSItemPushTypeToStr(APNSItemPushTypeBackground)]) {
40+
return APNSItemPushTypeBackground;
41+
}
42+
else if ([pushTypeStr isEqualToString:APNSItemPushTypeToStr(APNSItemPushTypeVoip)]) {
43+
return APNSItemPushTypeVoip;
44+
}
45+
else if ([pushTypeStr isEqualToString:APNSItemPushTypeToStr(APNSItemPushTypeComplication)]) {
46+
return APNSItemPushTypeComplication;
47+
}
48+
else if ([pushTypeStr isEqualToString:APNSItemPushTypeToStr(APNSItemPushTypeFileProvider)]) {
49+
return APNSItemPushTypeFileProvider;
50+
}
51+
else if ([pushTypeStr isEqualToString:APNSItemPushTypeToStr(APNSItemPushTypeMDM)]) {
52+
return APNSItemPushTypeMDM;
53+
}
54+
else {
55+
return APNSItemPushTypeDefault();
56+
}
57+
}
58+
59+
NSArray<NSString *> *APNSItemPushTypesAll(void) {
60+
return @[
61+
APNSItemPushTypeToStr(APNSItemPushTypeAlert),
62+
APNSItemPushTypeToStr(APNSItemPushTypeBackground),
63+
APNSItemPushTypeToStr(APNSItemPushTypeVoip),
64+
APNSItemPushTypeToStr(APNSItemPushTypeComplication),
65+
APNSItemPushTypeToStr(APNSItemPushTypeFileProvider),
66+
APNSItemPushTypeToStr(APNSItemPushTypeMDM),
67+
];
68+
}

0 commit comments

Comments
 (0)