Skip to content

Commit ef0da64

Browse files
committed
Creating OSPrivacyConsentController
This controller will now handle the setting and reading of NSUserDefaults for privacy consent. In the future requires privacy consent may involve remote parameters
1 parent c1b5695 commit ef0da64

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed

iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,9 @@
508508
DE7D18EE2703B5B9002D3A5D /* OSInAppMessagingRequests.m in Sources */ = {isa = PBXBuildFile; fileRef = DE7D18ED2703B5B9002D3A5D /* OSInAppMessagingRequests.m */; };
509509
DE7D18EF2703B5B9002D3A5D /* OSInAppMessagingRequests.m in Sources */ = {isa = PBXBuildFile; fileRef = DE7D18ED2703B5B9002D3A5D /* OSInAppMessagingRequests.m */; };
510510
DE7D18F02703B5B9002D3A5D /* OSInAppMessagingRequests.m in Sources */ = {isa = PBXBuildFile; fileRef = DE7D18ED2703B5B9002D3A5D /* OSInAppMessagingRequests.m */; };
511+
DE971752274C48B700FC409E /* OSPrivacyConsentController.m in Sources */ = {isa = PBXBuildFile; fileRef = DE971751274C48B700FC409E /* OSPrivacyConsentController.m */; };
512+
DE971754274C48CF00FC409E /* OSPrivacyConsentController.h in Headers */ = {isa = PBXBuildFile; fileRef = DE971753274C48CF00FC409E /* OSPrivacyConsentController.h */; settings = {ATTRIBUTES = (Public, ); }; };
513+
DE971755274C4B0C00FC409E /* OSPrivacyConsentController.m in Sources */ = {isa = PBXBuildFile; fileRef = DE971751274C48B700FC409E /* OSPrivacyConsentController.m */; };
511514
DE98772B2591656200DE07D5 /* NSDateFormatter+OneSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = DE98772A2591655800DE07D5 /* NSDateFormatter+OneSignal.m */; };
512515
DE9877332591656200DE07D5 /* NSDateFormatter+OneSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = DE98772A2591655800DE07D5 /* NSDateFormatter+OneSignal.m */; };
513516
DE9877342591656300DE07D5 /* NSDateFormatter+OneSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = DE98772A2591655800DE07D5 /* NSDateFormatter+OneSignal.m */; };
@@ -980,6 +983,8 @@
980983
DE7D18E42703B510002D3A5D /* OSLocationRequests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSLocationRequests.m; sourceTree = "<group>"; };
981984
DE7D18EB2703B5AA002D3A5D /* OSInAppMessagingRequests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSInAppMessagingRequests.h; sourceTree = "<group>"; };
982985
DE7D18ED2703B5B9002D3A5D /* OSInAppMessagingRequests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSInAppMessagingRequests.m; sourceTree = "<group>"; };
986+
DE971751274C48B700FC409E /* OSPrivacyConsentController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSPrivacyConsentController.m; sourceTree = "<group>"; };
987+
DE971753274C48CF00FC409E /* OSPrivacyConsentController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSPrivacyConsentController.h; sourceTree = "<group>"; };
983988
DE9877292591654600DE07D5 /* NSDateFormatter+OneSignal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSDateFormatter+OneSignal.h"; sourceTree = "<group>"; };
984989
DE98772A2591655800DE07D5 /* NSDateFormatter+OneSignal.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSDateFormatter+OneSignal.m"; sourceTree = "<group>"; };
985990
DE9A5DA925D1FD6B00FCEC21 /* OSPlayerTags.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSPlayerTags.h; sourceTree = "<group>"; };
@@ -1544,6 +1549,8 @@
15441549
DE7D187627037A16002D3A5D /* OneSignalCoreHelper.h */,
15451550
DE7D187827037A26002D3A5D /* OneSignalCoreHelper.m */,
15461551
7AE28B8725B8ADF400529100 /* OSMacros.h */,
1552+
DE971751274C48B700FC409E /* OSPrivacyConsentController.m */,
1553+
DE971753274C48CF00FC409E /* OSPrivacyConsentController.h */,
15471554
);
15481555
path = Source;
15491556
sourceTree = "<group>";
@@ -1841,6 +1848,7 @@
18411848
DE7D183D27027F13002D3A5D /* NSURL+OneSignal.h in Headers */,
18421849
DE7D17EB27026B95002D3A5D /* OneSignalCore.h in Headers */,
18431850
DE7D182A270271A9002D3A5D /* OneSignalCommonDefines.h in Headers */,
1851+
DE971754274C48CF00FC409E /* OSPrivacyConsentController.h in Headers */,
18441852
DE7D183627027AA0002D3A5D /* OneSignalLog.h in Headers */,
18451853
DE7D182D270273B0002D3A5D /* OSNotification.h in Headers */,
18461854
DE7D183F27027F62002D3A5D /* NSString+OneSignal.h in Headers */,
@@ -2365,6 +2373,7 @@
23652373
isa = PBXSourcesBuildPhase;
23662374
buildActionMask = 2147483647;
23672375
files = (
2376+
DE971755274C4B0C00FC409E /* OSPrivacyConsentController.m in Sources */,
23682377
DE7D186F2703751B002D3A5D /* OSRequests.m in Sources */,
23692378
7A94D8E1249ABF0000E90B40 /* OSUniqueOutcomeNotification.m in Sources */,
23702379
7AF8FDBD2332A5C200A19245 /* OSIndirectInfluence.m in Sources */,
@@ -2542,6 +2551,7 @@
25422551
DE7D183E27027F60002D3A5D /* NSString+OneSignal.m in Sources */,
25432552
DE7D17EA27026B95002D3A5D /* OneSignalCore.docc in Sources */,
25442553
DE7D18702703751B002D3A5D /* OSRequests.m in Sources */,
2554+
DE971752274C48B700FC409E /* OSPrivacyConsentController.m in Sources */,
25452555
DE7D182E270275FA002D3A5D /* OneSignalTrackFirebaseAnalytics.m in Sources */,
25462556
DE7D182827026F86002D3A5D /* OneSignalUserDefaults.m in Sources */,
25472557
);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
Modified MIT License
3+
4+
Copyright 2021 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+
29+
@interface OSPrivacyConsentController : NSObject
30+
+ (BOOL)requiresUserPrivacyConsent;
31+
+ (void)consentGranted:(BOOL)granted;
32+
+ (BOOL)shouldLogMissingPrivacyConsentErrorWithMethodName:(NSString *)methodName;
33+
@end
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
Modified MIT License
3+
4+
Copyright 2021 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+
29+
#import <Foundation/Foundation.h>
30+
#import "OSPrivacyConsentController.h"
31+
#import "OneSignalUserDefaults.h"
32+
#import "OneSignalCommonDefines.h"
33+
#import "OneSignalLog.h"
34+
35+
@implementation OSPrivacyConsentController
36+
37+
+ (BOOL)requiresUserPrivacyConsent {
38+
BOOL shouldRequireUserConsent = [OneSignalUserDefaults.initShared getSavedBoolForKey:OSUD_REQUIRES_USER_PRIVACY_CONSENT defaultValue:NO];
39+
// if the plist key does not exist default to true
40+
// the plist value specifies whether GDPR privacy consent is required for this app
41+
// if required and consent has not been previously granted, return false
42+
BOOL requiresConsent = [[[NSBundle mainBundle] objectForInfoDictionaryKey:ONESIGNAL_REQUIRE_PRIVACY_CONSENT] boolValue] ?: false;
43+
if (requiresConsent || shouldRequireUserConsent)
44+
return ![OneSignalUserDefaults.initStandard getSavedBoolForKey:GDPR_CONSENT_GRANTED defaultValue:false];
45+
46+
return false;
47+
}
48+
49+
+ (void)consentGranted:(BOOL)granted {
50+
[OneSignalUserDefaults.initStandard saveBoolForKey:GDPR_CONSENT_GRANTED withValue:granted];
51+
}
52+
53+
+ (BOOL)shouldLogMissingPrivacyConsentErrorWithMethodName:(NSString *)methodName {
54+
if ([self requiresUserPrivacyConsent]) {
55+
if (methodName) {
56+
[OneSignalLog onesignalLog:ONE_S_LL_WARN message:[NSString stringWithFormat:@"Your application has called %@ before the user granted privacy permission. Please call `consentGranted(bool)` in order to provide user privacy consent", methodName]];
57+
}
58+
return true;
59+
}
60+
61+
return false;
62+
}
63+
64+
@end

iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#import "OneSignalTrackFirebaseAnalytics.h"
4141
#import "OSMacros.h"
4242
#import "OSJSONHandling.h"
43+
#import "OSPrivacyConsentController.h"
4344

4445
@interface OneSignalCore : NSObject
4546

0 commit comments

Comments
 (0)