Skip to content

Commit 1f278a5

Browse files
committed
Add OneSignal to the NSE target
1 parent 322de24 commit 1f278a5

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed
Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,32 @@
1-
//
2-
// NotificationService.swift
3-
// OneSignalNotificationServiceExtension
4-
//
5-
// Created by Fadi George on 12/9/25.
6-
//
7-
81
import UserNotifications
2+
import OneSignalExtension
93

104
class NotificationService: UNNotificationServiceExtension {
11-
125
var contentHandler: ((UNNotificationContent) -> Void)?
6+
var receivedRequest: UNNotificationRequest!
137
var bestAttemptContent: UNMutableNotificationContent?
148

9+
// Note this extension only runs when `mutable_content` is set
10+
// Setting an attachment or action buttons automatically sets the property to true
1511
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
12+
self.receivedRequest = request
1613
self.contentHandler = contentHandler
17-
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
18-
14+
self.bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
15+
1916
if let bestAttemptContent = bestAttemptContent {
20-
// Modify the notification content here...
21-
bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"
22-
23-
contentHandler(bestAttemptContent)
17+
// DEBUGGING: Uncomment the 2 lines below to check this extension is executing
18+
// print("Running NotificationServiceExtension")
19+
// bestAttemptContent.body = "[Modified] " + bestAttemptContent.body
20+
21+
OneSignalExtension.didReceiveNotificationExtensionRequest(self.receivedRequest, with: bestAttemptContent, withContentHandler: self.contentHandler)
2422
}
2523
}
26-
24+
2725
override func serviceExtensionTimeWillExpire() {
28-
// Called just before the extension will be terminated by the system.
2926
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
3027
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
28+
OneSignalExtension.serviceExtensionTimeWillExpireRequest(self.receivedRequest, with: self.bestAttemptContent)
3129
contentHandler(bestAttemptContent)
3230
}
3331
}
34-
3532
}

examples/RNOneSignalTS/ios/Podfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ target 'RNOneSignalTS' do
3333
)
3434
end
3535
end
36+
37+
target 'OneSignalNotificationServiceExtension' do
38+
pod 'OneSignalXCFramework', '>= 5.0.0', '< 6.0'
39+
end

examples/RNOneSignalTS/ios/RNOneSignalTS.xcodeproj/project.pbxproj

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 70;
6+
objectVersion = 77;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -55,7 +55,7 @@
5555
/* End PBXFileReference section */
5656

5757
/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
58-
E8EFD7262EE8DE2A00D4BE2B /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
58+
E8EFD7262EE8DE2A00D4BE2B /* Exceptions for "OneSignalNotificationServiceExtension" folder in "OneSignalNotificationServiceExtension" target */ = {
5959
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
6060
membershipExceptions = (
6161
Info.plist,
@@ -65,7 +65,14 @@
6565
/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */
6666

6767
/* Begin PBXFileSystemSynchronizedRootGroup section */
68-
E8EFD71F2EE8DE2A00D4BE2B /* OneSignalNotificationServiceExtension */ = {isa = PBXFileSystemSynchronizedRootGroup; exceptions = (E8EFD7262EE8DE2A00D4BE2B /* PBXFileSystemSynchronizedBuildFileExceptionSet */, ); explicitFileTypes = {}; explicitFolders = (); path = OneSignalNotificationServiceExtension; sourceTree = "<group>"; };
68+
E8EFD71F2EE8DE2A00D4BE2B /* OneSignalNotificationServiceExtension */ = {
69+
isa = PBXFileSystemSynchronizedRootGroup;
70+
exceptions = (
71+
E8EFD7262EE8DE2A00D4BE2B /* Exceptions for "OneSignalNotificationServiceExtension" folder in "OneSignalNotificationServiceExtension" target */,
72+
);
73+
path = OneSignalNotificationServiceExtension;
74+
sourceTree = "<group>";
75+
};
6976
/* End PBXFileSystemSynchronizedRootGroup section */
7077

7178
/* Begin PBXFrameworksBuildPhase section */
@@ -215,14 +222,14 @@
215222
};
216223
};
217224
buildConfigurationList = 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "RNOneSignalTS" */;
218-
compatibilityVersion = "Xcode 12.0";
219225
developmentRegion = en;
220226
hasScannedForEncodings = 0;
221227
knownRegions = (
222228
en,
223229
Base,
224230
);
225231
mainGroup = 83CBB9F61A601CBA00E9B192;
232+
preferredProjectObjectVersion = 77;
226233
productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */;
227234
projectDirPath = "";
228235
projectRoot = "";

0 commit comments

Comments
 (0)