Skip to content

Commit b90e4ec

Browse files
authored
Added callback to set external user id (#633)
* Added callback to set external user id * WIP - Working on unit testing now * New public method exists now into OneSignal.h, so updates to the wrappers that require a header file will need to be made * Fixed caching of the external user id to now use OneSignalUserDefaults instead of NSUSerDefaults * WIP - Working on unit tests for set external id with callback * Added a completion block for the external user id update * Instead of success and failure, now it is simply overall completion because we have a push and email channel that needs to be updated * The param sent back is a NSDictionary with a channel @"push" or @"email" with a @"success" of 1 or 0 * Built a new OneSignalClient method for using the OSMultipleCompletionHandler now Updated demo app UI a bit for setting email, removing email, setting external user id, removing external user id * Change to response of external user id completion handler * true and false instead of 0 and 1 for the success key :value * Fixed and added unit tests for external id and email * Removed a not (!) check on accident for pending registering user with external id and is not already set to the same thing it is trying to update to * Placed the duplicate results generation into a sep method * Now when dup ext user id is being set we have a method for creating the response and including email or push when necessary * Addressing comment son previous commits * OSMultipleCompletionBlock to now return a NSDictionary * Added a TODO addressing the new executeSimultaneousRequests method and how we should use this in the future
1 parent c3ab33f commit b90e4ec

File tree

11 files changed

+565
-189
lines changed

11 files changed

+565
-189
lines changed

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

Lines changed: 130 additions & 49 deletions
Large diffs are not rendered by default.

iOS_SDK/OneSignalDevApp/OneSignalDevApp/ViewController.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,29 @@
3333

3434
@interface ViewController : UIViewController <OSInAppMessageDelegate>
3535

36-
@property (weak, nonatomic) IBOutlet UITextField *appIdTextField;
3736
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicatorView;
3837
@property (weak, nonatomic) IBOutlet UISegmentedControl *consentSegmentedControl;
38+
@property (weak, nonatomic) IBOutlet UITextField *appIdTextField;
39+
@property (weak, nonatomic) IBOutlet UIButton *updateAppIdButton;
40+
@property (weak, nonatomic) IBOutlet UIButton *getTagsButton;
41+
@property (weak, nonatomic) IBOutlet UIButton *sendTagsButton;
42+
@property (weak, nonatomic) IBOutlet UIButton *promptPushButton;
43+
@property (weak, nonatomic) IBOutlet UIButton *promptLocationButton;
3944
@property (weak, nonatomic) IBOutlet UISegmentedControl *subscriptionSegmentedControl;
45+
@property (weak, nonatomic) IBOutlet UITextField *emailTextField;
46+
@property (weak, nonatomic) IBOutlet UIButton *setEmailButton;
47+
@property (weak, nonatomic) IBOutlet UIButton *logoutEmailButton;
48+
@property (weak, nonatomic) IBOutlet UITextField *externalUserIdTextField;
49+
@property (weak, nonatomic) IBOutlet UIButton *setExternalUserIdButton;
50+
@property (weak, nonatomic) IBOutlet UIButton *removeExternalUserIdButton;
4051
@property (weak, nonatomic) IBOutlet UISegmentedControl *locationSharedSegementedControl;
4152
@property (weak, nonatomic) IBOutlet UISegmentedControl *inAppMessagingSegmentedControl;
42-
@property (weak, nonatomic) IBOutlet UIButton *promptPushButton;
43-
@property (weak, nonatomic) IBOutlet UIButton *promptLocationButton;
4453
@property (weak, nonatomic) IBOutlet UITextField *addTriggerKey;
4554
@property (weak, nonatomic) IBOutlet UITextField *addTriggerValue;
4655
@property (weak, nonatomic) IBOutlet UIButton *addTriggerButton;
4756
@property (weak, nonatomic) IBOutlet UITextField *removeTriggerKey;
4857
@property (weak, nonatomic) IBOutlet UITextField *getTriggerKey;
4958
@property (weak, nonatomic) IBOutlet UILabel *infoLabel;
50-
@property (weak, nonatomic) IBOutlet UITextField *externalIdTextField;
5159
@property (weak, nonatomic) IBOutlet UITextField *outcomeName;
5260
@property (weak, nonatomic) IBOutlet UITextField *outcomeValueName;
5361
@property (weak, nonatomic) IBOutlet UITextField *outcomeValue;

iOS_SDK/OneSignalDevApp/OneSignalDevApp/ViewController.m

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,33 @@ - (IBAction)getTriggersAction:(id)sender {
8484
}
8585
}
8686

87+
- (IBAction)setEmailButton:(id)sender {
88+
NSString *email = self.emailTextField.text;
89+
[OneSignal setEmail:email withSuccess:^{
90+
NSLog(@"Set email successful with email: %@", email);
91+
} withFailure:^(NSError *error) {
92+
NSLog(@"Set email failed with code: %@ and message: %@", @(error.code), error.description);
93+
}];
94+
}
95+
96+
- (IBAction)logoutEmailButton:(id)sender {
97+
[OneSignal logoutEmailWithSuccess:^{
98+
NSLog(@"Email logout successful");
99+
} withFailure:^(NSError *error) {
100+
NSLog(@"Error logging out email with code: %@ and message: %@", @(error.code), error.description);
101+
}];
102+
}
103+
104+
- (IBAction)getTagsButton:(id)sender {
105+
[OneSignal IdsAvailable:^(NSString *userId, NSString *pushToken) {
106+
NSLog(@"IdsAvailable userId: %@, and pushToken: %@", userId, pushToken);
107+
}];
108+
109+
[OneSignal getTags:^(NSDictionary *result) {
110+
NSLog(@"Tags: %@", result.description);
111+
}];
112+
}
113+
87114
- (IBAction)sendTagButton:(id)sender {
88115
[OneSignal sendTag:@"key1"
89116
value:@"value1"
@@ -95,10 +122,6 @@ - (IBAction)sendTagButton:(id)sender {
95122
static int failures = 0;
96123
NSLog(@"failures: %d", ++failures);
97124
}];
98-
99-
[OneSignal IdsAvailable:^(NSString *userId, NSString *pushToken) {
100-
NSLog(@"IdsAvailable Fired");
101-
}];
102125
}
103126

104127
- (IBAction)promptPushAction:(UIButton *)sender {
@@ -113,10 +136,6 @@ - (IBAction)promptLocationAction:(UIButton *)sender {
113136
[OneSignal promptLocation];
114137
}
115138

116-
- (IBAction)setEmailButtonPressed:(UIButton *)sender {
117-
[AppDelegate setOneSignalAppId:self.appIdTextField.text];
118-
}
119-
120139
- (void)promptForNotificationsWithNativeiOS10Code {
121140
id responseBlock = ^(BOOL granted, NSError* error) {
122141
NSLog(@"promptForNotificationsWithNativeiOS10Code: %d", granted);
@@ -152,12 +171,21 @@ - (IBAction)inAppMessagingSegmentedControlValueChanged:(UISegmentedControl *)sen
152171
[OneSignal pauseInAppMessages:(bool) !sender.selectedSegmentIndex];
153172
}
154173

155-
-(void)handleMessageAction:(NSString *)actionId {
174+
- (void)handleMessageAction:(NSString *)actionId {
156175
NSLog(@"View controller did get action: %@", actionId);
157176
}
158177

159-
- (IBAction)removeExternalIdButtonPressed:(UIButton *)sender {
160-
[OneSignal removeExternalUserId];
178+
- (IBAction)setExternalUserId:(UIButton *)sender {
179+
NSString* externalUserId = self.externalUserIdTextField.text;
180+
[OneSignal setExternalUserId:externalUserId withCompletion:^(NSDictionary *results) {
181+
NSLog(@"External user id update complete with results: %@", results.description);
182+
}];
183+
}
184+
185+
- (IBAction)removeExternalUserId:(UIButton *)sender {
186+
[OneSignal removeExternalUserId:^(NSDictionary *results) {
187+
NSLog(@"External user id update complete with results: %@", results.description);
188+
}];
161189
}
162190

163191
#pragma mark UITextFieldDelegate Methods

iOS_SDK/OneSignalSDK/Source/OneSignal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,13 @@ typedef void (^OSEmailSuccessBlock)();
507507

508508

509509
// External user id
510+
// Typedefs defining completion blocks for updating the external user id
511+
typedef void (^OSUpdateExternalUserIdBlock)(NSDictionary* results);
512+
510513
+ (void)setExternalUserId:(NSString * _Nonnull)externalId;
514+
+ (void)setExternalUserId:(NSString * _Nonnull)externalId withCompletion:(OSUpdateExternalUserIdBlock _Nullable)completionBlock;
511515
+ (void)removeExternalUserId;
516+
+ (void)removeExternalUserId:(OSUpdateExternalUserIdBlock _Nullable)completionBlock;
512517

513518
// In-App Messaging triggers
514519
+ (void)addTrigger:(NSString * _Nonnull)key withValue:(id _Nonnull)value;

0 commit comments

Comments
 (0)