Skip to content

Commit 2006f04

Browse files
committed
Add delayed language network call
* Add OneSignalSetLanguageParameters * OneSignalSetLanguageParameters stores language network call information when prior to user initialization * On creating new session, delayed language parameters are retrieved and network call is made
1 parent 1e1482c commit 2006f04

File tree

3 files changed

+100
-2
lines changed

3 files changed

+100
-2
lines changed

iOS_SDK/OneSignalSDK/Source/OneSignal.m

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
#import "OneSignalSetEmailParameters.h"
7575
#import "OneSignalSetSMSParameters.h"
7676
#import "OneSignalSetExternalIdParameters.h"
77+
#import "OneSignalSetLanguageParameters.h"
7778
#import "DelayedConsentInitializationParameters.h"
7879
#import "OneSignalDialogController.h"
7980

@@ -146,6 +147,7 @@ + (OneSignalSetSMSParameters *)delayedSMSParameters {
146147
return _delayedSMSParameters;
147148
}
148149
static OneSignalSetExternalIdParameters *delayedExternalIdParameters;
150+
static OneSignalSetLanguageParameters *delayedLanguageParameters;
149151

150152
static NSMutableArray* pendingSendTagCallbacks;
151153
static OSResultSuccessBlock pendingGetTagsSuccessBlock;
@@ -1886,6 +1888,12 @@ + (void)registerUserInternal {
18861888
_delayedSMSParameters = nil;
18871889
}
18881890

1891+
if (delayedLanguageParameters) {
1892+
// Call to setLanguage: was delayed because the push player_id did not exist yet
1893+
[self setLanguage:delayedLanguageParameters.language withSuccess:delayedLanguageParameters.successBlock withFailure:delayedLanguageParameters.failureBlock];
1894+
delayedLanguageParameters = nil;
1895+
}
1896+
18891897
if (nowProcessingCallbacks) {
18901898
for (OSPendingCallbacks *callbackSet in nowProcessingCallbacks) {
18911899
if (callbackSet.successBlock)
@@ -1896,8 +1904,6 @@ + (void)registerUserInternal {
18961904
if (self.playerTags.tagsToSend) {
18971905
[self performSelector:@selector(sendTagsToServer) withObject:nil afterDelay:5];
18981906
}
1899-
1900-
//TODO: Check for Pending Language State and add a put call for it
19011907

19021908
// Try to send location
19031909
[OneSignalLocation sendLocation];
@@ -2726,6 +2732,17 @@ + (void)setLanguage:(NSString * _Nonnull)language withSuccess:(OSUpdateLanguageS
27262732

27272733
+ (void)setLanguageOnServer:(NSString * _Nonnull)language WithSuccess:(OSUpdateLanguageSuccessBlock)successBlock withFailure:(OSUpdateLanguageFailureBlock)failureBlock {
27282734

2735+
if ([language isEqualToString:@""]) {
2736+
failureBlock([NSError errorWithDomain:@"com.onesignal.language" code:0 userInfo:@{@"error" : @"Empty Language Code"}]);
2737+
return;
2738+
}
2739+
2740+
if (!self.currentSubscriptionState.userId || _downloadedParameters == false) {
2741+
[self onesignal_Log:ONE_S_LL_VERBOSE message:@"iOS Parameters for this application has not yet been downloaded. Delaying call to setLanguage: until the parameters have been downloaded."];
2742+
delayedLanguageParameters = [OneSignalSetLanguageParameters language:language withSuccess:successBlock withFailure:failureBlock];
2743+
return;
2744+
}
2745+
27292746
[OneSignal.stateSynchronizer updateLanguage:language appId:appId withSuccess:^(NSDictionary *results) {
27302747
if (successBlock)
27312748
successBlock(results);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
#import <Foundation/Foundation.h>
29+
#import "OneSignal.h"
30+
31+
@interface OneSignalSetLanguageParameters : NSObject
32+
33+
+ (instancetype _Nullable )language:(NSString * _Nonnull)language withSuccess:(OSUpdateLanguageSuccessBlock _Nullable)successBlock withFailure:(OSUpdateLanguageFailureBlock _Nullable)failureBlock;
34+
35+
@property (strong, nonatomic, nonnull) NSString *language;
36+
@property (nonatomic, nullable) OSResultSuccessBlock successBlock;
37+
@property (nonatomic, nullable) OSFailureBlock failureBlock;
38+
39+
@end
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
#import "OneSignalSetLanguageParameters.h"
29+
30+
@implementation OneSignalSetLanguageParameters
31+
32+
+ (instancetype)language:(NSString * _Nonnull)language withSuccess:(OSUpdateLanguageSuccessBlock _Nullable)success withFailure:(OSUpdateLanguageFailureBlock _Nullable)failure {
33+
OneSignalSetLanguageParameters *parameters = [OneSignalSetLanguageParameters new];
34+
35+
parameters.language = language;
36+
parameters.successBlock = success;
37+
parameters.failureBlock = failure;
38+
39+
return parameters;
40+
}
41+
42+
@end

0 commit comments

Comments
 (0)