Skip to content

Commit a1bef2c

Browse files
authored
Media attachments service extension (#198)
* Notification Service Extension is now used instead of content-available on iOS 10 for Action buttons and Media attachments. * This improves the reliably of and delivery speed of notifications with these features enabled. * Added the following selectors that must be used with from your Notification Service Extension. + didReceiveNotificatioExtensionnRequest:withMutableNotificationContent: + serviceExtensionTimeWillExpireRequest:withMutableNotificationContent: * Fixed bug where actionID was not being set since release 2.3.6. * Cleaned up Objective-c example project * Added additional unit test and fixed flaky tests with Travis-CI * Fixed crash with action buttons when using the new os_data payload.
1 parent c80e55e commit a1bef2c

File tree

22 files changed

+618
-519
lines changed

22 files changed

+618
-519
lines changed

OneSignal.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ Pod::Spec.new do |s|
1212
s.requires_arc = true
1313

1414
s.ios.vendored_frameworks = 'iOS_SDK/Framework/OneSignal.framework'
15-
s.framework = 'SystemConfiguration'
15+
s.framework = 'SystemConfiguration', 'UIKit'
1616
end

OneSignalExample/OSServiceExtension/Info.plist renamed to OneSignalExample/NotificationServiceExtension/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<key>CFBundleDevelopmentRegion</key>
66
<string>en</string>
77
<key>CFBundleDisplayName</key>
8-
<string>OSServiceExtension</string>
8+
<string>NotificationServiceExtension</string>
99
<key>CFBundleExecutable</key>
1010
<string>$(EXECUTABLE_NAME)</string>
1111
<key>CFBundleIdentifier</key>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Modified MIT License
3+
*
4+
* Copyright 2017 OneSignal
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* 1. The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* 2. All copies of substantial portions of the Software may only be used in connection
17+
* with services provided by OneSignal.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#import <UserNotifications/UserNotifications.h>
29+
30+
@interface NotificationService : UNNotificationServiceExtension
31+
32+
@end
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* Modified MIT License
3+
*
4+
* Copyright 2017 OneSignal
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* 1. The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* 2. All copies of substantial portions of the Software may only be used in connection
17+
* with services provided by OneSignal.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#import <OneSignal/OneSignal.h>
29+
30+
#import "NotificationService.h"
31+
32+
@interface NotificationService ()
33+
34+
@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
35+
@property (nonatomic, strong) UNNotificationRequest *recievedRequest;
36+
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
37+
38+
@end
39+
40+
@implementation NotificationService
41+
42+
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
43+
self.recievedRequest = request;
44+
self.contentHandler = contentHandler;
45+
self.bestAttemptContent = [request.content mutableCopy];
46+
47+
[OneSignal didReceiveNotificatioExtensionnRequest:self.recievedRequest withMutableNotificationContent:self.bestAttemptContent];
48+
49+
self.contentHandler(self.bestAttemptContent);
50+
}
51+
52+
- (void)serviceExtensionTimeWillExpire {
53+
// Called just before the extension will be terminated by the system.
54+
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
55+
56+
[OneSignal serviceExtensionTimeWillExpireRequest:self.recievedRequest withMutableNotificationContent:self.bestAttemptContent];
57+
58+
self.contentHandler(self.bestAttemptContent);
59+
}
60+
61+
@end

OneSignalExample/OSContentExension/Base.lproj/MainInterface.storyboard

Lines changed: 0 additions & 50 deletions
This file was deleted.

OneSignalExample/OSContentExension/Info.plist

Lines changed: 0 additions & 38 deletions
This file was deleted.

OneSignalExample/OSContentExension/NotificationViewController.h

Lines changed: 0 additions & 13 deletions
This file was deleted.

OneSignalExample/OSContentExension/NotificationViewController.m

Lines changed: 0 additions & 30 deletions
This file was deleted.

OneSignalExample/OSServiceExtension/NotificationService.h

Lines changed: 0 additions & 13 deletions
This file was deleted.

OneSignalExample/OSServiceExtension/NotificationService.m

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)