Skip to content

Commit 3745009

Browse files
committed
Make a MockMessagingController
* Make a `MockMessagingController` in Objective C to allow us to access internal APIs on the OSMessagingController without needing to make them public. This is needed because Swift code cannot access Objective-C APIs unless they are public. This is a workaround for this limitation.
1 parent af77fe9 commit 3745009

File tree

5 files changed

+88
-2
lines changed

5 files changed

+88
-2
lines changed

iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,6 +1748,7 @@
17481748
3C43986C2D38C70400EFBD2C /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
17491749
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
17501750
publicHeaders = (
1751+
MockMessagingController.h,
17511752
OneSignalInAppMessagesMocks.h,
17521753
);
17531754
target = 3C4398602D38C70400EFBD2C /* OneSignalInAppMessagesMocks */;

iOS_SDK/OneSignalSDK/OneSignalInAppMessagesMocks/IAMTestHelpers.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,5 @@ public class IAMTestHelpers: NSObject {
9494
return [
9595
"in_app_messages" : messages
9696
]
97-
9897
}
9998
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Modified MIT License
3+
4+
Copyright 2025 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 <Foundation/Foundation.h>
29+
#import <OneSignalCore/OneSignalCore.h>
30+
31+
NS_ASSUME_NONNULL_BEGIN
32+
33+
@interface MockMessagingController : NSObject
34+
+ (NSArray <OSInAppMessage *> *)messageDisplayQueue; // TODO: may need to be changed to return OSInAppMessageInternal
35+
+ (BOOL)isInAppMessageShowing;
36+
@end
37+
38+
NS_ASSUME_NONNULL_END
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Modified MIT License
3+
4+
Copyright 2025 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 "MockMessagingController.h"
29+
#import "OSMessagingController.h"
30+
31+
@interface OSMessagingController ()
32+
@property (strong, nonatomic, nonnull) NSMutableArray <OSInAppMessageInternal *> *messageDisplayQueue;
33+
@end
34+
35+
@implementation MockMessagingController
36+
+ (void)resetState {
37+
// TODO: reseting OSMessagingController state between tests
38+
}
39+
40+
+ (NSArray *)messageDisplayQueue {
41+
return OSMessagingController.sharedInstance.messageDisplayQueue;
42+
}
43+
44+
+ (BOOL)isInAppMessageShowing {
45+
return OSMessagingController.sharedInstance.isInAppMessageShowing;
46+
}
47+
48+
@end

iOS_SDK/OneSignalSDK/OneSignalInAppMessagesMocks/OneSignalInAppMessagesMocks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ FOUNDATION_EXPORT const unsigned char OneSignalInAppMessagesMocksVersionString[]
3535

3636
// In this header, you should import all the public headers of your framework using statements like #import <OneSignalInAppMessagesMocks/PublicHeader.h>
3737

38-
38+
#import <OneSignalInAppMessagesMocks/MockMessagingController.h>

0 commit comments

Comments
 (0)