Skip to content

Commit f25e9bf

Browse files
committed
Make OneSignalCore class to hold module's services
- Make a OneSignalCore class through which the services of this module can be set and accessed - To start, make a protocol for OneSignalClient, IOneSignalClient (name of protocol TBD)
1 parent aaf9d32 commit f25e9bf

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed

iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
3C9AD6DF2B22A8EC00BC1540 /* OneSignalNotifications.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DEF784292912DEB600A1F3A5 /* OneSignalNotifications.framework */; };
109109
3C9AD6E02B22A8EC00BC1540 /* OneSignalNotifications.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = DEF784292912DEB600A1F3A5 /* OneSignalNotifications.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
110110
3CA6CE0A28E4F19B00CA0585 /* OSUserRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CA6CE0928E4F19B00CA0585 /* OSUserRequest.swift */; };
111+
3CC063942B6D6B6B002BB07F /* OneSignalCore.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CC063932B6D6B6B002BB07F /* OneSignalCore.m */; };
111112
3CC9A6342AFA1FDE008F68FD /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 3CC9A6332AFA1FDD008F68FD /* PrivacyInfo.xcprivacy */; };
112113
3CC9A6362AFA26E7008F68FD /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 3CC9A6352AFA26E7008F68FD /* PrivacyInfo.xcprivacy */; };
113114
3CCF44BE299B17290021964D /* OneSignalWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 3CCF44BC299B17290021964D /* OneSignalWrapper.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -816,6 +817,7 @@
816817
3C9AD6D02B228B9200BC1540 /* OSRequestRemoveAlias.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSRequestRemoveAlias.swift; sourceTree = "<group>"; };
817818
3C9AD6D22B228BB000BC1540 /* OSRequestUpdateProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSRequestUpdateProperties.swift; sourceTree = "<group>"; };
818819
3CA6CE0928E4F19B00CA0585 /* OSUserRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSUserRequest.swift; sourceTree = "<group>"; };
820+
3CC063932B6D6B6B002BB07F /* OneSignalCore.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OneSignalCore.m; sourceTree = "<group>"; };
819821
3CC9A6332AFA1FDD008F68FD /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
820822
3CC9A6352AFA26E7008F68FD /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
821823
3CCF44BC299B17290021964D /* OneSignalWrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OneSignalWrapper.h; sourceTree = "<group>"; };
@@ -1745,6 +1747,7 @@
17451747
isa = PBXGroup;
17461748
children = (
17471749
DE7D17E827026B95002D3A5D /* OneSignalCore.h */,
1750+
3CC063932B6D6B6B002BB07F /* OneSignalCore.m */,
17481751
DEF7848E2914798400A1F3A5 /* Swizzling */,
17491752
DEF7845A2912E89200A1F3A5 /* OSObservable.h */,
17501753
DEF7845B2912E89200A1F3A5 /* OSObservable.m */,
@@ -3091,6 +3094,7 @@
30913094
DE7D182E270275FA002D3A5D /* OneSignalTrackFirebaseAnalytics.m in Sources */,
30923095
DE51DDE5294262AB0073D5C4 /* OSRemoteParamController.m in Sources */,
30933096
DE7D182827026F86002D3A5D /* OneSignalUserDefaults.m in Sources */,
3097+
3CC063942B6D6B6B002BB07F /* OneSignalCore.m in Sources */,
30943098
);
30953099
runOnlyForDeploymentPostprocessing = 0;
30963100
};

iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OneSignalClient.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@
3131
#ifndef OneSignalClient_h
3232
#define OneSignalClient_h
3333

34-
@interface OneSignalClient : NSObject
35-
+ (OneSignalClient *)sharedClient;
34+
@protocol IOneSignalClient <NSObject>
3635
- (void)executeRequest:(OneSignalRequest *)request onSuccess:(OSResultSuccessBlock)successBlock onFailure:(OSFailureBlock)failureBlock;
3736
@end
3837

38+
@interface OneSignalClient : NSObject <IOneSignalClient>
39+
+ (OneSignalClient *)sharedClient;
40+
@end
41+
3942
#endif

iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCore.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,11 @@
5656
#import <OneSignalCore/OneSignalWrapper.h>
5757
#import <OneSignalCore/OSInAppMessages.h>
5858
#import <OneSignalCore/OSLocation.h>
59+
60+
// TODO: Testing: Should this class be defined in this file?
61+
@interface OneSignalCore : NSObject
62+
63+
+ (void)setSharedClient:(nonnull id<IOneSignalClient>)client;
64+
+ (nonnull id<IOneSignalClient>)sharedClient;
65+
66+
@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 2024 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.h"
30+
31+
@implementation OneSignalCore
32+
33+
static id<IOneSignalClient> _sharedClient;
34+
+ (id<IOneSignalClient>)sharedClient {
35+
if (!_sharedClient) {
36+
// If tests didn't set their own client, we will default to this
37+
return OneSignalClient.sharedClient;
38+
}
39+
return _sharedClient;
40+
}
41+
42+
+ (void)setSharedClient:(id<IOneSignalClient>)client {
43+
_sharedClient = client;
44+
}
45+
46+
@end

0 commit comments

Comments
 (0)