Skip to content

Commit ecdd49a

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 0768f8d commit ecdd49a

File tree

4 files changed

+112
-1
lines changed

4 files changed

+112
-1
lines changed

iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj

+25
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@
5858
3C0C67172D493E5A00F80448 /* IAMTestHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C0C67162D493E5A00F80448 /* IAMTestHelpers.swift */; };
5959
3C0C671C2D49449C00F80448 /* OneSignalInAppMessages.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DEBAAE282A4211D900BF2C1C /* OneSignalInAppMessages.framework */; };
6060
3C0C671D2D49449C00F80448 /* OneSignalInAppMessages.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = DEBAAE282A4211D900BF2C1C /* OneSignalInAppMessages.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
61+
3C0C67232D49469200F80448 /* MockMessagingController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C0C67222D49469200F80448 /* MockMessagingController.m */; };
62+
3C0C67242D49469200F80448 /* MockMessagingController.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C0C67212D49469200F80448 /* MockMessagingController.h */; settings = {ATTRIBUTES = (Public, ); }; };
63+
3C0C67252D4946BD00F80448 /* OneSignalCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DE7D17E627026B95002D3A5D /* OneSignalCore.framework */; };
64+
3C0C67262D4946BD00F80448 /* OneSignalCore.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = DE7D17E627026B95002D3A5D /* OneSignalCore.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
6165
3C0EF49E28A1DBCB00E5434B /* OSUserInternalImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C0EF49D28A1DBCB00E5434B /* OSUserInternalImpl.swift */; };
6266
3C115165289A259500565C41 /* OneSignalOSCore.docc in Sources */ = {isa = PBXBuildFile; fileRef = 3C115164289A259500565C41 /* OneSignalOSCore.docc */; };
6367
3C115171289A259500565C41 /* OneSignalOSCore.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C115163289A259500565C41 /* OneSignalOSCore.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -637,6 +641,13 @@
637641
remoteGlobalIDString = DEBAAE272A4211D900BF2C1C;
638642
remoteInfo = OneSignalInAppMessages;
639643
};
644+
3C0C67272D4946BD00F80448 /* PBXContainerItemProxy */ = {
645+
isa = PBXContainerItemProxy;
646+
containerPortal = 37747F8B19147D6400558FAD /* Project object */;
647+
proxyType = 1;
648+
remoteGlobalIDString = DE7D17E527026B95002D3A5D;
649+
remoteInfo = OneSignalCore;
650+
};
640651
3C115194289AF85400565C41 /* PBXContainerItemProxy */ = {
641652
isa = PBXContainerItemProxy;
642653
containerPortal = 37747F8B19147D6400558FAD /* Project object */;
@@ -1125,6 +1136,7 @@
11251136
dstPath = "";
11261137
dstSubfolderSpec = 10;
11271138
files = (
1139+
3C0C67262D4946BD00F80448 /* OneSignalCore.framework in Embed Frameworks */,
11281140
3C0C671D2D49449C00F80448 /* OneSignalInAppMessages.framework in Embed Frameworks */,
11291141
);
11301142
name = "Embed Frameworks";
@@ -1268,6 +1280,8 @@
12681280
3C01518E2C2E298E0079E076 /* OneSignalInAppMessagesTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OneSignalInAppMessagesTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
12691281
3C01519B2C2E29F90079E076 /* IAMRequestTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IAMRequestTests.m; sourceTree = "<group>"; };
12701282
3C0C67162D493E5A00F80448 /* IAMTestHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IAMTestHelpers.swift; sourceTree = "<group>"; };
1283+
3C0C67212D49469200F80448 /* MockMessagingController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockMessagingController.h; sourceTree = "<group>"; };
1284+
3C0C67222D49469200F80448 /* MockMessagingController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MockMessagingController.m; sourceTree = "<group>"; };
12711285
3C0EF49D28A1DBCB00E5434B /* OSUserInternalImpl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OSUserInternalImpl.swift; sourceTree = "<group>"; };
12721286
3C115161289A259500565C41 /* OneSignalOSCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = OneSignalOSCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
12731287
3C115163289A259500565C41 /* OneSignalOSCore.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OneSignalOSCore.h; sourceTree = "<group>"; };
@@ -1767,6 +1781,7 @@
17671781
isa = PBXFrameworksBuildPhase;
17681782
buildActionMask = 2147483647;
17691783
files = (
1784+
3C0C67252D4946BD00F80448 /* OneSignalCore.framework in Frameworks */,
17701785
3C0C671C2D49449C00F80448 /* OneSignalInAppMessages.framework in Frameworks */,
17711786
);
17721787
runOnlyForDeploymentPostprocessing = 0;
@@ -2171,6 +2186,8 @@
21712186
children = (
21722187
3C3FABD72D4898E500B7090D /* OneSignalInAppMessagesMocks.h */,
21732188
3C0C67162D493E5A00F80448 /* IAMTestHelpers.swift */,
2189+
3C0C67212D49469200F80448 /* MockMessagingController.h */,
2190+
3C0C67222D49469200F80448 /* MockMessagingController.m */,
21742191
);
21752192
path = OneSignalInAppMessagesMocks;
21762193
sourceTree = "<group>";
@@ -3117,6 +3134,7 @@
31173134
buildActionMask = 2147483647;
31183135
files = (
31193136
3C3FABD92D4898E500B7090D /* OneSignalInAppMessagesMocks.h in Headers */,
3137+
3C0C67242D49469200F80448 /* MockMessagingController.h in Headers */,
31203138
);
31213139
runOnlyForDeploymentPostprocessing = 0;
31223140
};
@@ -3396,6 +3414,7 @@
33963414
);
33973415
dependencies = (
33983416
3C0C671F2D49449C00F80448 /* PBXTargetDependency */,
3417+
3C0C67282D4946BD00F80448 /* PBXTargetDependency */,
33993418
);
34003419
name = OneSignalInAppMessagesMocks;
34013420
packageProductDependencies = (
@@ -4287,6 +4306,7 @@
42874306
isa = PBXSourcesBuildPhase;
42884307
buildActionMask = 2147483647;
42894308
files = (
4309+
3C0C67232D49469200F80448 /* MockMessagingController.m in Sources */,
42904310
3C0C67172D493E5A00F80448 /* IAMTestHelpers.swift in Sources */,
42914311
);
42924312
runOnlyForDeploymentPostprocessing = 0;
@@ -4692,6 +4712,11 @@
46924712
target = DEBAAE272A4211D900BF2C1C /* OneSignalInAppMessages */;
46934713
targetProxy = 3C0C671E2D49449C00F80448 /* PBXContainerItemProxy */;
46944714
};
4715+
3C0C67282D4946BD00F80448 /* PBXTargetDependency */ = {
4716+
isa = PBXTargetDependency;
4717+
target = DE7D17E527026B95002D3A5D /* OneSignalCore */;
4718+
targetProxy = 3C0C67272D4946BD00F80448 /* PBXContainerItemProxy */;
4719+
};
46954720
3C115195289AF85400565C41 /* PBXTargetDependency */ = {
46964721
isa = PBXTargetDependency;
46974722
target = DE7D17E527026B95002D3A5D /* OneSignalCore */;
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
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

+1-1
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)