Skip to content

Commit 0e25931

Browse files
authored
Gdpr privacy (#361)
* Privacy Consent • Adds the capability to require user privacy consent before the SDK can be initialized * Revoke Consent • Made it so that when the user revokes consent after granting it, the SDK will immediately stop sending any information to the server • Added checks in some internal methods to make sure personal data is never sent when consent is revoked or not provided * Improve Consent • Adds consent checks to location data so that the SDK will not send location data if consent is revoked • Adds nullability specifiers to the new DelayedInitializationParameters class * Add Test • Adds a test to make sure the privacy consent functionality works correctly, delays initialization, and resumes correctly. * Add Consent Setting Override • Adds a method to override the plist consent setting, intended for wrapper SDK's that cannot use a plist setting * Download Params • Changes the SDK so that iOS params are still downloaded even if the user has not provided consent yet (to make things faster if they do eventually provide consent) • Added additional checks to ensure that the SDK will _never_ initiate an HTTP request (asides from GET requests) if the user has not provided consent • Adds test to make sure that swizzled methods (ie. didRegisterForRemoteNotifications) do not initiate HTTP requests or change state (ie. push token) if consent has not been granted • Adds a test to make sure the OneSignal setRequiresUserPrivacyConsent: override method works correctly • Adds a check to make sure handleNotificationOpened: does not execute if the user has not provided consent * Plist Capitalization • Changes the privacy consent parameter name capitalization from Onesignal_require_privacy_consent to OneSignal_require_privacy_consent to be more consistent
1 parent a9275a9 commit 0e25931

File tree

16 files changed

+539
-23
lines changed

16 files changed

+539
-23
lines changed

iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
4141
[FIRApp configure];
4242

4343
NSLog(@"Bundle URL: %@", [[NSBundle mainBundle] bundleURL]);
44-
NSLog(@"[[NSUUID alloc] initWithUUIDString:nil]: %@", [[NSUUID alloc] initWithUUIDString:nil]);
4544

46-
[OneSignal setLogLevel:ONE_S_LL_VERBOSE visualLevel:ONE_S_LL_WARN];
45+
[OneSignal setLogLevel:ONE_S_LL_VERBOSE visualLevel:ONE_S_LL_ERROR];
4746

4847
OneSignal.inFocusDisplayType = OSNotificationDisplayTypeInAppAlert;
4948

iOS_SDK/OneSignalDevApp/OneSignalDevApp/Base.lproj/Main.storyboard

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<dependencies>
77
<deployment identifier="iOS"/>
88
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
9+
<capability name="Alignment constraints with different attributes" minToolsVersion="5.1"/>
910
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
1011
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
1112
</dependencies>
@@ -71,24 +72,53 @@
7172
<constraint firstAttribute="height" constant="20" id="bBI-BW-dmM"/>
7273
</constraints>
7374
</activityIndicatorView>
75+
<segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" translatesAutoresizingMaskIntoConstraints="NO" id="05S-ud-V2e">
76+
<rect key="frame" x="163" y="442" width="179" height="29"/>
77+
<constraints>
78+
<constraint firstAttribute="height" constant="28" id="nSO-fn-AxS"/>
79+
</constraints>
80+
<segments>
81+
<segment title="Not Granted"/>
82+
<segment title="Granted"/>
83+
</segments>
84+
<connections>
85+
<action selector="consentSegmentedControlValueChanged:" destination="BYZ-38-t0r" eventType="valueChanged" id="oL2-15-pJ0"/>
86+
</connections>
87+
</segmentedControl>
88+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Consent Status:" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="j3e-42-uww">
89+
<rect key="frame" x="0.0" y="445" width="155" height="21"/>
90+
<constraints>
91+
<constraint firstAttribute="height" constant="21" id="sCD-KJ-VyV"/>
92+
</constraints>
93+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
94+
<nil key="textColor"/>
95+
<nil key="highlightedColor"/>
96+
</label>
7497
</subviews>
7598
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
7699
<constraints>
100+
<constraint firstItem="05S-ud-V2e" firstAttribute="leading" secondItem="j3e-42-uww" secondAttribute="trailing" constant="8" id="0VK-or-IQV"/>
77101
<constraint firstItem="H3K-GA-smE" firstAttribute="centerX" secondItem="ebC-zs-TnD" secondAttribute="centerX" id="1J0-KC-Ike"/>
78102
<constraint firstItem="Kp7-Oh-BQ1" firstAttribute="top" secondItem="H3K-GA-smE" secondAttribute="bottom" constant="56" id="467-jK-M0h"/>
79103
<constraint firstItem="ebC-zs-TnD" firstAttribute="top" secondItem="H3K-GA-smE" secondAttribute="bottom" constant="18" id="4gc-Du-Gk7"/>
104+
<constraint firstItem="05S-ud-V2e" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="centerX" constant="-24.5" id="8TC-JA-qOE"/>
80105
<constraint firstItem="Kp7-Oh-BQ1" firstAttribute="centerX" secondItem="H3K-GA-smE" secondAttribute="centerX" id="BET-RV-SSL"/>
106+
<constraint firstItem="05S-ud-V2e" firstAttribute="top" secondItem="0cV-KP-U0v" secondAttribute="bottom" constant="18" id="Doq-ct-llI"/>
81107
<constraint firstItem="k3C-y9-O4O" firstAttribute="leading" secondItem="ebC-zs-TnD" secondAttribute="trailing" constant="8" id="EHn-dg-Gsx"/>
82108
<constraint firstAttribute="trailingMargin" secondItem="ebC-zs-TnD" secondAttribute="trailing" constant="54" id="NSB-la-nXF"/>
83109
<constraint firstItem="k3C-y9-O4O" firstAttribute="centerY" secondItem="ebC-zs-TnD" secondAttribute="centerY" id="WyY-eM-1NM"/>
110+
<constraint firstItem="j3e-42-uww" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="XLa-mE-TYD"/>
84111
<constraint firstItem="ebC-zs-TnD" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="Yug-OZ-HIr"/>
112+
<constraint firstAttribute="trailing" secondItem="05S-ud-V2e" secondAttribute="trailing" constant="33" id="en0-C1-hCf"/>
85113
<constraint firstItem="0cV-KP-U0v" firstAttribute="centerX" secondItem="Kp7-Oh-BQ1" secondAttribute="centerX" id="rAQ-XU-eNr"/>
114+
<constraint firstItem="j3e-42-uww" firstAttribute="centerY" secondItem="05S-ud-V2e" secondAttribute="centerY" id="thm-36-AAy"/>
86115
<constraint firstItem="ebC-zs-TnD" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" constant="54" id="tp6-Bq-3wr"/>
87116
<constraint firstItem="0cV-KP-U0v" firstAttribute="top" secondItem="Kp7-Oh-BQ1" secondAttribute="bottom" constant="8" id="wyD-rc-wek"/>
88117
</constraints>
89118
</view>
90119
<connections>
91120
<outlet property="activityIndicatorView" destination="k3C-y9-O4O" id="cIe-9k-ZJW"/>
121+
<outlet property="consentSegmentedControl" destination="05S-ud-V2e" id="9HS-Rj-OmM"/>
92122
<outlet property="textField" destination="ebC-zs-TnD" id="Qds-Dp-amQ"/>
93123
</connections>
94124
</viewController>

iOS_SDK/OneSignalDevApp/OneSignalDevApp/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5+
<key>OneSignal_require_privacy_consent</key>
6+
<true/>
57
<key>CFBundleDevelopmentRegion</key>
68
<string>en</string>
79
<key>CFBundleExecutable</key>

iOS_SDK/OneSignalDevApp/OneSignalDevApp/ViewController.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
@interface ViewController ()
3636
@property (weak, nonatomic) IBOutlet UITextField *textField;
3737
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicatorView;
38+
@property (weak, nonatomic) IBOutlet UISegmentedControl *consentSegmentedControl;
3839

3940
@end
4041

@@ -45,6 +46,8 @@ - (void)viewDidLoad {
4546
// Do any additional setup after loading the view, typically from a nib.
4647

4748
self.activityIndicatorView.hidden = true;
49+
50+
self.consentSegmentedControl.selectedSegmentIndex = (NSInteger)![OneSignal requiresUserPrivacyConsent];
4851
}
4952

5053
- (void)changeAnimationState:(BOOL)animating {
@@ -121,5 +124,10 @@ - (void)didReceiveMemoryWarning {
121124
// Dispose of any resources that can be recreated.
122125
}
123126

127+
- (IBAction)consentSegmentedControlValueChanged:(UISegmentedControl *)sender {
128+
NSLog(@"View controller consent granted: %i", (int)sender.selectedSegmentIndex);
129+
[OneSignal consentGranted:(bool)sender.selectedSegmentIndex];
130+
}
131+
124132

125133
@end

iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@
153153
CAABF34B205B15780042F8E5 /* OneSignalExtensionBadgeHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = CAABF34A205B15780042F8E5 /* OneSignalExtensionBadgeHandler.m */; };
154154
CAABF34C205B157B0042F8E5 /* OneSignalExtensionBadgeHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = CAABF34A205B15780042F8E5 /* OneSignalExtensionBadgeHandler.m */; };
155155
CAABF34D205B157B0042F8E5 /* OneSignalExtensionBadgeHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = CAABF34A205B15780042F8E5 /* OneSignalExtensionBadgeHandler.m */; };
156+
CAB4112920852E48005A70D1 /* DelayedInitializationParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = CAB4112820852E48005A70D1 /* DelayedInitializationParameters.m */; };
157+
CAB4112A20852E4C005A70D1 /* DelayedInitializationParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = CAB4112820852E48005A70D1 /* DelayedInitializationParameters.m */; };
158+
CAB4112B20852E4C005A70D1 /* DelayedInitializationParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = CAB4112820852E48005A70D1 /* DelayedInitializationParameters.m */; };
156159
CAB411AE208931EE005A70D1 /* DummyNotificationCenterDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = CAB411AD208931EE005A70D1 /* DummyNotificationCenterDelegate.m */; };
157160
CAEA1C66202BB3C600FBFE9E /* OSEmailSubscription.h in Headers */ = {isa = PBXBuildFile; fileRef = CA810FCF202BA97300A60FED /* OSEmailSubscription.h */; };
158161
/* End PBXBuildFile section */
@@ -293,6 +296,8 @@
293296
CAA4ED0020646762005BD59B /* BadgeTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BadgeTests.m; sourceTree = "<group>"; };
294297
CAABF349205B15780042F8E5 /* OneSignalExtensionBadgeHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OneSignalExtensionBadgeHandler.h; sourceTree = "<group>"; };
295298
CAABF34A205B15780042F8E5 /* OneSignalExtensionBadgeHandler.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OneSignalExtensionBadgeHandler.m; sourceTree = "<group>"; };
299+
CAB4112720852E48005A70D1 /* DelayedInitializationParameters.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DelayedInitializationParameters.h; sourceTree = "<group>"; };
300+
CAB4112820852E48005A70D1 /* DelayedInitializationParameters.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DelayedInitializationParameters.m; sourceTree = "<group>"; };
296301
CAB411AC208931EE005A70D1 /* DummyNotificationCenterDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DummyNotificationCenterDelegate.h; sourceTree = "<group>"; };
297302
CAB411AD208931EE005A70D1 /* DummyNotificationCenterDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DummyNotificationCenterDelegate.m; sourceTree = "<group>"; };
298303
/* End PBXFileReference section */
@@ -448,6 +453,8 @@
448453
91C7725D1E7CCE1000D612D0 /* OneSignalInternal.h */,
449454
912411F01E73342200E41FD7 /* OneSignal.h */,
450455
912411F11E73342200E41FD7 /* OneSignal.m */,
456+
CAB4112720852E48005A70D1 /* DelayedInitializationParameters.h */,
457+
CAB4112820852E48005A70D1 /* DelayedInitializationParameters.m */,
451458
CA70E3332023D51000019273 /* OneSignalSetEmailParameters.h */,
452459
CA70E3342023D51000019273 /* OneSignalSetEmailParameters.m */,
453460
912411F41E73342200E41FD7 /* OneSignalHelper.h */,
@@ -736,6 +743,7 @@
736743
9124123A1E73342200E41FD7 /* OneSignalWebView.m in Sources */,
737744
9124123E1E73342200E41FD7 /* UIApplicationDelegate+OneSignal.m in Sources */,
738745
912412261E73342200E41FD7 /* OneSignalMobileProvision.m in Sources */,
746+
CAB4112920852E48005A70D1 /* DelayedInitializationParameters.m in Sources */,
739747
454F94F21FAD218000D74CCF /* OneSignalNotificationServiceExtensionHandler.m in Sources */,
740748
912412321E73342200E41FD7 /* OneSignalTracker.m in Sources */,
741749
CA70E3352023D51000019273 /* OneSignalSetEmailParameters.m in Sources */,
@@ -774,6 +782,7 @@
774782
0338566B1FBBD2270002F7C1 /* OSNotificationPayload.m in Sources */,
775783
912412431E73342200E41FD7 /* UNUserNotificationCenter+OneSignal.m in Sources */,
776784
9124123B1E73342200E41FD7 /* OneSignalWebView.m in Sources */,
785+
CAB4112A20852E4C005A70D1 /* DelayedInitializationParameters.m in Sources */,
777786
9124123F1E73342200E41FD7 /* UIApplicationDelegate+OneSignal.m in Sources */,
778787
0338566C1FBBDB150002F7C1 /* OneSignalNotificationServiceExtensionHandler.m in Sources */,
779788
CA70E3362023D51300019273 /* OneSignalSetEmailParameters.m in Sources */,
@@ -814,6 +823,7 @@
814823
912412491E73369800E41FD7 /* OneSignalHelper.m in Sources */,
815824
4529DEE41FA82C6200CEAB1D /* NSURLSessionOverrider.m in Sources */,
816825
4529DED21FA81EA800CEAB1D /* NSObjectOverrider.m in Sources */,
826+
CAB4112B20852E4C005A70D1 /* DelayedInitializationParameters.m in Sources */,
817827
912412341E73342200E41FD7 /* OneSignalTracker.m in Sources */,
818828
912412101E73342200E41FD7 /* OneSignal.m in Sources */,
819829
9124122C1E73342200E41FD7 /* OneSignalReachability.m in Sources */,
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Modified MIT License
3+
*
4+
* Copyright 2017 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 "OneSignal.h"
30+
31+
@interface DelayedInitializationParameters : NSObject
32+
33+
-(instancetype _Nonnull)initWithLaunchOptions:(NSDictionary * _Nullable)launchOptions withAppId:(NSString * _Nullable)appId withHandleNotificationReceivedBlock:(OSHandleNotificationReceivedBlock _Nullable)received withHandleNotificationActionBlock:(OSHandleNotificationActionBlock _Nullable)action withSettings:(NSDictionary * _Nullable)settings;
34+
35+
@property (strong, nonatomic, nullable) NSDictionary *launchOptions;
36+
@property (strong, nonatomic, nullable) NSString *appId;
37+
@property (strong, nonatomic, nullable) NSDictionary *settings;
38+
@property (nonatomic, nullable) OSHandleNotificationReceivedBlock receivedBlock;
39+
@property (nonatomic, nullable) OSHandleNotificationActionBlock actionBlock;
40+
41+
@end
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Modified MIT License
3+
*
4+
* Copyright 2017 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 "DelayedInitializationParameters.h"
29+
30+
@implementation DelayedInitializationParameters
31+
32+
-(instancetype)initWithLaunchOptions:(NSDictionary *)launchOptions withAppId:(NSString *)appId withHandleNotificationReceivedBlock:(OSHandleNotificationReceivedBlock)received withHandleNotificationActionBlock:(OSHandleNotificationActionBlock)action withSettings:(NSDictionary *)settings {
33+
self.launchOptions = launchOptions;
34+
self.appId = appId;
35+
self.receivedBlock = received;
36+
self.actionBlock = action;
37+
self.settings = settings;
38+
return self;
39+
}
40+
41+
@end

iOS_SDK/OneSignalSDK/Source/OneSignal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@ typedef NS_ENUM(NSUInteger, ONE_S_LOG_LEVEL) {
340340
+ (id)initWithLaunchOptions:(NSDictionary*)launchOptions appId:(NSString*)appId handleNotificationAction:(OSHandleNotificationActionBlock)actionCallback settings:(NSDictionary*)settings;
341341
+ (id)initWithLaunchOptions:(NSDictionary*)launchOptions appId:(NSString*)appId handleNotificationReceived:(OSHandleNotificationReceivedBlock)receivedCallback handleNotificationAction:(OSHandleNotificationActionBlock)actionCallback settings:(NSDictionary*)settings;
342342

343+
// - Privacy
344+
+ (void)consentGranted:(BOOL)granted;
345+
+ (BOOL)requiresUserPrivacyConsent; // tells your application if privacy consent is still needed from the current user
346+
+ (void)setRequiresUserPrivacyConsent:(BOOL)required; //used by wrapper SDK's to require user privacy consent
347+
343348
@property (class) OSNotificationDisplayType inFocusDisplayType;
344349

345350
+ (NSString*)app_id;

0 commit comments

Comments
 (0)