Skip to content

Commit 8d6c6ce

Browse files
authored
Merge pull request #963 from OneSignal/feature/interruption_and_relevance_score
Interruption Level and Relevance Score
2 parents 3672cc2 + 5ec16bb commit 8d6c6ce

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

iOS_SDK/OneSignalSDK/Source/OSNotification.m

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,20 @@ - (void)parseOtherApnsFields {
189189
if (aps[@"thread-id"]) {
190190
_threadId = (NSString *)aps[@"thread-id"];
191191
}
192+
193+
if (aps[@"relevance-score"]) {
194+
_relevanceScore = (NSNumber *)aps[@"relevance-score"];
195+
}
196+
197+
if (aps[@"interruption-level"]) {
198+
_interruptionLevel = (NSString *)aps[@"interruption-level"];
199+
}
192200

193201
_category = aps[@"category"];
194202
}
195203

196204
- (NSString *)description {
197-
return [NSString stringWithFormat: @"notificationId=%@ templateId=%@ templateName=%@ contentAvailable=%@ mutableContent=%@ category=%@ rawPayload=%@", _notificationId, _templateId, _templateName, _contentAvailable ? @"YES" : @"NO", _mutableContent ? @"YES" : @"NO", _category, _rawPayload];
205+
return [NSString stringWithFormat: @"notificationId=%@ templateId=%@ templateName=%@ contentAvailable=%@ mutableContent=%@ category=%@ relevanceScore=%@ interruptionLevel=%@ rawPayload=%@", _notificationId, _templateId, _templateName, _contentAvailable ? @"YES" : @"NO", _mutableContent ? @"YES" : @"NO", _category, _relevanceScore, _interruptionLevel, _rawPayload];
198206
}
199207

200208
- (NSDictionary *)jsonRepresentation {
@@ -253,6 +261,12 @@ - (NSDictionary *)jsonRepresentation {
253261

254262
if (self.category)
255263
[obj setObject:self.category forKeyedSubscript: @"category"];
264+
265+
if (self.relevanceScore)
266+
[obj setObject:self.relevanceScore forKeyedSubscript: @"relevanceScore"];
267+
268+
if (self.interruptionLevel)
269+
[obj setObject:self.interruptionLevel forKeyedSubscript: @"interruptionLevel"];
256270

257271
return obj;
258272
}

iOS_SDK/OneSignalSDK/Source/OneSignal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ typedef NS_ENUM(NSUInteger, OSNotificationActionType) {
130130
/* iOS 10+ : Groups notifications into threads */
131131
@property(readonly, nullable)NSString *threadId;
132132

133+
/* iOS 15+ : Relevance Score for notification summary */
134+
@property(readonly, nullable)NSNumber *relevanceScore;
135+
136+
/* iOS 15+ : Interruption Level */
137+
@property(readonly)NSString *interruptionLevel;
138+
133139
/* Parses an APNS push payload into a OSNotification object.
134140
Useful to call from your NotificationServiceExtension when the
135141
didReceiveNotificationRequest:withContentHandler: method fires. */

iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3114,6 +3114,8 @@ - (void)testNotificationJson {
31143114
@"content-available": @1,
31153115
@"mutable-content": @1,
31163116
@"alert": @"Message Body",
3117+
@"relevance-score": @0.15,
3118+
@"interruption-level": @"time-sensitive",
31173119
},
31183120
@"os_data": @{
31193121
@"i": @"notif id",

0 commit comments

Comments
 (0)