Skip to content

Commit 5ea8674

Browse files
committed
Moving getCompletionBlock to a category in OneSignalFramework
This allows us to use UIApplication sharedApplication since it is not included in OneSignalCore. To accomplish this I created an OSNotification category in OneSignalFramework. I needed to expose the complete method to do this.
1 parent 0540578 commit 5ea8674

File tree

6 files changed

+94
-17
lines changed

6 files changed

+94
-17
lines changed

iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,10 @@
382382
DE367CC824EEF2BE00165207 /* OSInAppMessagePage.m in Sources */ = {isa = PBXBuildFile; fileRef = DE367CC624EEF2BE00165207 /* OSInAppMessagePage.m */; };
383383
DE367CC924EEF2BE00165207 /* OSInAppMessagePage.m in Sources */ = {isa = PBXBuildFile; fileRef = DE367CC624EEF2BE00165207 /* OSInAppMessagePage.m */; };
384384
DE367CCA24EEF2C800165207 /* OSInAppMessagePage.h in Headers */ = {isa = PBXBuildFile; fileRef = DE367CC524EEF2A800165207 /* OSInAppMessagePage.h */; };
385+
DE3CD2F9270F9A6D00A5BECD /* OSNotification+OneSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = DE3CD2F8270F9A6D00A5BECD /* OSNotification+OneSignal.m */; };
386+
DE3CD2FA270F9A6D00A5BECD /* OSNotification+OneSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = DE3CD2F8270F9A6D00A5BECD /* OSNotification+OneSignal.m */; };
387+
DE3CD2FB270F9A6D00A5BECD /* OSNotification+OneSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = DE3CD2F8270F9A6D00A5BECD /* OSNotification+OneSignal.m */; };
388+
DE3CD2FD270F9A8100A5BECD /* OSNotification+OneSignal.h in Headers */ = {isa = PBXBuildFile; fileRef = DE3CD2FC270F9A8100A5BECD /* OSNotification+OneSignal.h */; };
385389
DE5EFECA24D8DBF70032632D /* OSInAppMessageViewControllerOverrider.m in Sources */ = {isa = PBXBuildFile; fileRef = DE5EFEC924D8DBF70032632D /* OSInAppMessageViewControllerOverrider.m */; };
386390
DE7D17EA27026B95002D3A5D /* OneSignalCore.docc in Sources */ = {isa = PBXBuildFile; fileRef = DE7D17E927026B95002D3A5D /* OneSignalCore.docc */; };
387391
DE7D17EB27026B95002D3A5D /* OneSignalCore.h in Headers */ = {isa = PBXBuildFile; fileRef = DE7D17E827026B95002D3A5D /* OneSignalCore.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -931,6 +935,8 @@
931935
DE20425D24E21C2C00350E4F /* UIApplication+OneSignal.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIApplication+OneSignal.m"; sourceTree = "<group>"; };
932936
DE367CC524EEF2A800165207 /* OSInAppMessagePage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSInAppMessagePage.h; sourceTree = "<group>"; };
933937
DE367CC624EEF2BE00165207 /* OSInAppMessagePage.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSInAppMessagePage.m; sourceTree = "<group>"; };
938+
DE3CD2F8270F9A6D00A5BECD /* OSNotification+OneSignal.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "OSNotification+OneSignal.m"; sourceTree = "<group>"; };
939+
DE3CD2FC270F9A8100A5BECD /* OSNotification+OneSignal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "OSNotification+OneSignal.h"; sourceTree = "<group>"; };
934940
DE5EFEC924D8DBF70032632D /* OSInAppMessageViewControllerOverrider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSInAppMessageViewControllerOverrider.m; sourceTree = "<group>"; };
935941
DE5EFECB24D8DC0E0032632D /* OSInAppMessageViewControllerOverrider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSInAppMessageViewControllerOverrider.h; sourceTree = "<group>"; };
936942
DE7D17E627026B95002D3A5D /* OneSignalCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = OneSignalCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -1354,6 +1360,8 @@
13541360
DE20425D24E21C2C00350E4F /* UIApplication+OneSignal.m */,
13551361
DE9877292591654600DE07D5 /* NSDateFormatter+OneSignal.h */,
13561362
DE98772A2591655800DE07D5 /* NSDateFormatter+OneSignal.m */,
1363+
DE3CD2FC270F9A8100A5BECD /* OSNotification+OneSignal.h */,
1364+
DE3CD2F8270F9A6D00A5BECD /* OSNotification+OneSignal.m */,
13571365
);
13581366
name = Categories;
13591367
sourceTree = "<group>";
@@ -1776,6 +1784,7 @@
17761784
DE9A5DAA25D1FD6B00FCEC21 /* OSPlayerTags.h in Headers */,
17771785
91B6EA451E86555200B5CF01 /* OSObservable.h in Headers */,
17781786
DE367CCA24EEF2C800165207 /* OSInAppMessagePage.h in Headers */,
1787+
DE3CD2FD270F9A8100A5BECD /* OSNotification+OneSignal.h in Headers */,
17791788
CACBAA9C218A6243000ACAA5 /* OSInAppMessageView.h in Headers */,
17801789
912412351E73342200E41FD7 /* OneSignalTrackIAP.h in Headers */,
17811790
7AECE59423674AA700537907 /* OSAttributedFocusTimeProcessor.h in Headers */,
@@ -2243,6 +2252,7 @@
22432252
7A42744225CDE98E00EE75FC /* OSSMSSubscription.m in Sources */,
22442253
7A5E726225A66EA400CB5605 /* OSStateSynchronizer.m in Sources */,
22452254
91B6EA411E85D38F00B5CF01 /* OSObservable.m in Sources */,
2255+
DE3CD2F9270F9A6D00A5BECD /* OSNotification+OneSignal.m in Sources */,
22462256
DE7D18EE2703B5B9002D3A5D /* OSInAppMessagingRequests.m in Sources */,
22472257
DE367CC724EEF2BE00165207 /* OSInAppMessagePage.m in Sources */,
22482258
7A676BE524981CEC003957CC /* OSDeviceState.m in Sources */,
@@ -2321,6 +2331,7 @@
23212331
912412271E73342200E41FD7 /* OneSignalMobileProvision.m in Sources */,
23222332
912412331E73342200E41FD7 /* OneSignalTracker.m in Sources */,
23232333
DE367CC824EEF2BE00165207 /* OSInAppMessagePage.m in Sources */,
2334+
DE3CD2FA270F9A6D00A5BECD /* OSNotification+OneSignal.m in Sources */,
23242335
DE7D18EF2703B5B9002D3A5D /* OSInAppMessagingRequests.m in Sources */,
23252336
91B6EA421E85D38F00B5CF01 /* OSObservable.m in Sources */,
23262337
A63E9E3C26742B5F00EA273E /* LanguageContext.m in Sources */,
@@ -2405,6 +2416,7 @@
24052416
CAB269E221B2038B00F8A43C /* OSInAppMessageBridgeEvent.m in Sources */,
24062417
9D1BD96A237A28FC00A064F7 /* OSCachedUniqueOutcome.m in Sources */,
24072418
CAA4ED0120646762005BD59B /* BadgeTests.m in Sources */,
2419+
DE3CD2FB270F9A6D00A5BECD /* OSNotification+OneSignal.m in Sources */,
24082420
7A5E726425A66EA400CB5605 /* OSStateSynchronizer.m in Sources */,
24092421
7AF9866C244975CF00C36EAE /* OSOutcomeSource.m in Sources */,
24102422
912412491E73369800E41FD7 /* OneSignalHelper.m in Sources */,

iOS_SDK/OneSignalSDK/OneSignalCore/Source/OSNotification+Internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
+(instancetype _Nonnull )parseWithApns:(nonnull NSDictionary *)message;
3535
- (void)setCompletionBlock:(OSNotificationDisplayResponse _Nonnull)completion;
3636
- (void)startTimeoutTimer;
37-
- (OSNotificationDisplayResponse _Nullable)getCompletionBlock;
37+
- (void)complete:(OSNotification *)notification;
3838
@end
3939

4040
#endif /* OSNotification_Internal_h */

iOS_SDK/OneSignalSDK/OneSignalCore/Source/OSNotification.m

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -306,22 +306,6 @@ - (void)setCompletionBlock:(OSNotificationDisplayResponse)completion {
306306
_completion = completion;
307307
}
308308

309-
- (OSNotificationDisplayResponse)getCompletionBlock {
310-
OSNotificationDisplayResponse block = ^(OSNotification *notification){
311-
/*
312-
If notification is null here then display was cancelled and we need to
313-
reset the badge count to the value prior to receipt of this notif
314-
*/
315-
if (!notification) {
316-
// ECM TODO: We can't use sharedApplication in Core
317-
//NSInteger previousBadgeCount = [UIApplication sharedApplication].applicationIconBadgeNumber;
318-
[OneSignalUserDefaults.initShared saveIntegerForKey:ONESIGNAL_BADGE_KEY withValue:0];
319-
}
320-
[self complete:notification];
321-
};
322-
return block;
323-
}
324-
325309
- (void)complete:(OSNotification *)notification {
326310
[_timeoutTimer invalidate];
327311
if (_completion) {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Modified MIT License
3+
*
4+
* Copyright 2021OneSignal
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+
29+
#import <Foundation/Foundation.h>
30+
#import <OneSignalCore/OneSignalCore.h>
31+
32+
@interface OSNotification (OneSignal)
33+
- (OSNotificationDisplayResponse _Nullable)getCompletionBlock;
34+
@end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Modified MIT License
3+
*
4+
* Copyright 2021OneSignal
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+
29+
#import "OSNotification+OneSignal.h"
30+
#import <UIKit/UIKit.h>
31+
@implementation OSNotification (OneSignal)
32+
- (OSNotificationDisplayResponse)getCompletionBlock {
33+
OSNotificationDisplayResponse block = ^(OSNotification *notification){
34+
/*
35+
If notification is null here then display was cancelled and we need to
36+
reset the badge count to the value prior to receipt of this notif
37+
*/
38+
if (!notification) {
39+
NSInteger previousBadgeCount = [UIApplication sharedApplication].applicationIconBadgeNumber;
40+
[OneSignalUserDefaults.initShared saveIntegerForKey:ONESIGNAL_BADGE_KEY withValue:previousBadgeCount];
41+
}
42+
[self complete:notification];
43+
};
44+
return block;
45+
}
46+
@end

iOS_SDK/OneSignalSDK/Source/OneSignalHelper.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#import "OSMessagingController.h"
4141
#import "OneSignalNotificationCategoryController.h"
4242
#import "OneSignalReceiveReceiptsController.h"
43+
#import "OSNotification+OneSignal.h"
4344

4445
#define NOTIFICATION_TYPE_ALL 7
4546
#pragma clang diagnostic push

0 commit comments

Comments
 (0)