Skip to content

Commit 73d8271

Browse files
author
queue-it
committed
Preparing release 3.0.8
1 parent 786baee commit 73d8271

14 files changed

+166
-85
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ QueueITLib.xcworkspace/xcuserdata/queut-it.xcuserdatad/xcdebugger/**
22
QueueITLib.xcworkspace/xcuserdata
33
QueueITLib.xcworkspace
44
builds
5-
xcuserdata/
5+
xcuserdata/
6+
/.idea

QueueITLib/IOSUtils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#import <Foundation/Foundation.h>
2+
#import "QueueConsts.h"
23

34
@interface IOSUtils : NSObject
45
+(NSString*)getUserId;

QueueITLib/IOSUtils.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ +(NSString*)getLibraryVersion{
3939
}
4040

4141
+(NSString*)getSdkVersion{
42-
return @"iOS-3.0.7";
42+
return SDKVersion;
4343
}
4444

4545
@end

QueueITLib/QueueConsts.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
#define QueueConsts_h
33

44
#define QueueCloseUrl @"queueit://close"
5+
#define QueueRestartSessionUrl @"queueit://restartSession"
6+
#define SDKVersion @"iOS-3.0.8";
57

68
#endif

QueueITLib/QueueITEngine.h

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
@protocol QueueITUnavailableDelegate;
99
@protocol QueueUserExitedDelegate;
1010
@protocol QueueViewClosedDelegate;
11+
@protocol QueueSessionRestartDelegate;
1112

1213
@interface QueueITEngine : NSObject
1314
@property (nonatomic)id<QueuePassedDelegate> queuePassedDelegate;
@@ -16,6 +17,7 @@
1617
@property (nonatomic)id<QueueITUnavailableDelegate> queueITUnavailableDelegate;
1718
@property (nonatomic)id<QueueUserExitedDelegate> queueUserExitedDelegate;
1819
@property (nonatomic)id<QueueViewClosedDelegate> queueViewClosedDelegate;
20+
@property (nonatomic)id<QueueSessionRestartDelegate> queueSessionRestartDelegate;
1921
@property (nonatomic, strong)NSString* errorMessage;
2022

2123
typedef enum {
@@ -32,24 +34,33 @@ typedef enum {
3234

3335
-(void)setViewDelay:(int)delayInterval;
3436
-(BOOL)run:(NSError **)error;
35-
-(void)raiseQueuePassed:(NSString*) queueitToken;
37+
-(BOOL)runWithEnqueueToken:(NSString*) enqueueToken
38+
error:(NSError **) error;
39+
-(BOOL)runWithEnqueueKey:(NSString*) enqueueKey
40+
error:(NSError **) error;
3641
-(BOOL)isUserInQueue;
3742
-(BOOL)isRequestInProgress;
3843
-(NSString*) errorTypeEnumToString:(QueueITRuntimeError)errorEnumVal;
39-
-(void)raiseUserExited;
4044
-(void)updateQueuePageUrl:(NSString*)queuePageUrl;
45+
-(void)raiseUserExited;
4146
-(void)raiseViewClosed;
42-
-(void)close: (void (^ __nullable)(void))onComplete;
43-
-(void)handleAppEnqueueResponse:(NSString*) queueId
44-
queueURL:(NSString*) queueURL
47+
-(void)raiseSessionRestart;
48+
-(void)raiseQueuePassed:(NSString*) queueitToken;
49+
-(void)close:(void (^ __nullable)(void))onComplete;
50+
-(void)handleAppEnqueueResponse:(NSString* _Nullable) queueId
51+
queueURL:(NSString* _Nullable) queueURL
4552
queueURLTTLInMinutes:(int) ttl
46-
eventTargetURL:(NSString*) targetURL
47-
queueItToken:(NSString*) token;
53+
eventTargetURL:(NSString* _Nullable) targetURL
54+
queueItToken:(NSString* _Nullable) token;
4855

4956
@end
5057

5158
@protocol QueuePassedDelegate <NSObject>
52-
-(void)notifyYourTurn:(QueuePassedInfo*) queuePassedInfo;
59+
-(void)notifyYourTurn:(QueuePassedInfo* _Nullable) queuePassedInfo;
60+
@end
61+
62+
@protocol QueueSessionRestartDelegate <NSObject>
63+
-(void)notifySessionRestart;
5364
@end
5465

5566
@protocol QueueViewWillOpenDelegate <NSObject>
@@ -61,7 +72,7 @@ typedef enum {
6172
@end
6273

6374
@protocol QueueITUnavailableDelegate <NSObject>
64-
-(void)notifyQueueITUnavailable: (NSString *) errorMessage;
75+
-(void)notifyQueueITUnavailable:(NSString *) errorMessage;
6576
@end
6677

6778
@protocol QueueUserExitedDelegate <NSObject>

QueueITLib/QueueITEngine.m

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ -(instancetype)initWithHost:(UIViewController *)host customerId:(NSString*)custo
4646
return self;
4747
}
4848

49-
-(void)close: (void (^ __nullable)(void))onComplete
49+
-(void)close:(void (^ __nullable)(void))onComplete
5050
{
5151
NSLog(@"Closing webview");
5252
if(currentWebView!=nil){
@@ -94,7 +94,26 @@ -(BOOL)isRequestInProgress {
9494
return self.requestInProgress;
9595
}
9696

97+
-(BOOL)runWithEnqueueKey:(NSString *)enqueueKey
98+
error:(NSError *__autoreleasing *)error
99+
{
100+
return [self runWithParameters:nil enqueueKey:enqueueKey error:error];
101+
}
102+
103+
-(BOOL)runWithEnqueueToken:(NSString *)enqueueToken
104+
error:(NSError *__autoreleasing *)error
105+
{
106+
return [self runWithParameters:enqueueToken enqueueKey:nil error:error];
107+
}
108+
97109
-(BOOL)run:(NSError **)error
110+
{
111+
return [self runWithParameters:nil enqueueKey:nil error:error];
112+
}
113+
114+
-(BOOL)runWithParameters:(NSString*)enqueueToken
115+
enqueueKey:(NSString*)enqueueKey
116+
error:(NSError**)error
98117
{
99118
if(![self checkConnection:error]){
100119
return NO;
@@ -109,7 +128,7 @@ -(BOOL)run:(NSError **)error
109128
self.requestInProgress = YES;
110129

111130
if (![self tryShowQueueFromCache]) {
112-
[self tryEnqueue];
131+
[self tryEnqueue:enqueueToken enqueueKey:enqueueKey];
113132
}
114133

115134
return YES;
@@ -138,11 +157,11 @@ -(void)showQueue:(NSString*)queueUrl targetUrl:(NSString*)targetUrl
138157
[self raiseQueueViewWillOpen];
139158

140159
QueueITWKViewController *queueWKVC = [[QueueITWKViewController alloc] initWithHost:self.host
141-
queueEngine:self
142-
queueUrl:queueUrl
143-
eventTargetUrl:targetUrl
144-
customerId:self.customerId
145-
eventId:self.eventId];
160+
queueEngine:self
161+
queueUrl:queueUrl
162+
eventTargetUrl:targetUrl
163+
customerId:self.customerId
164+
eventId:self.eventId];
146165
currentWebView = queueWKVC;
147166

148167
if (@available(iOS 13.0, *)) {
@@ -159,10 +178,11 @@ -(void)showQueue:(NSString*)queueUrl targetUrl:(NSString*)targetUrl
159178
}
160179
}
161180

162-
-(void)tryEnqueue
181+
-(void)tryEnqueue:(NSString*)enqueueToken
182+
enqueueKey:(NSString*)enqueueKey
163183
{
164184
[IOSUtils getUserAgent:^(NSString * userAgent) {
165-
[self tryEnqueueWithUserAgent:userAgent];
185+
[self tryEnqueueWithUserAgent:userAgent enqueueToken:enqueueToken enqueueKey:enqueueKey];
166186
}];
167187
}
168188

@@ -211,6 +231,8 @@ -(void)handleAppEnqueueResponse:(NSString*) queueId
211231
}
212232

213233
-(void)tryEnqueueWithUserAgent:(NSString*)secretAgent
234+
enqueueToken:(NSString*)enqueueToken
235+
enqueueKey:(NSString*)enqueueKey
214236
{
215237
NSString* userId = [IOSUtils getUserId];
216238
NSString* userAgent = [NSString stringWithFormat:@"%@;%@", secretAgent, [IOSUtils getLibraryVersion]];
@@ -219,41 +241,45 @@ -(void)tryEnqueueWithUserAgent:(NSString*)secretAgent
219241
QueueService* qs = [QueueService sharedInstance];
220242
[qs enqueue:self.customerId
221243
eventOrAliasId:self.eventId
222-
userId:userId userAgent:userAgent
244+
userId:userId
245+
userAgent:userAgent
223246
sdkVersion:sdkVersion
224247
layoutName:self.layoutName
225248
language:self.language
249+
enqueueToken:enqueueToken
250+
enqueueKey:enqueueKey
226251
success:^(QueueStatus *queueStatus)
227252
{
228-
if (queueStatus == NULL) {
229-
[self enqueueRetryMonitor];
230-
return;
231-
}
232-
253+
if (queueStatus == NULL) {
254+
[self enqueueRetryMonitor:enqueueToken enqueueKey:enqueueKey];
255+
return;
256+
}
257+
233258
[self handleAppEnqueueResponse: queueStatus.queueId
234259
queueURL:queueStatus.queueUrlString
235260
queueURLTTLInMinutes:queueStatus.queueUrlTTL
236261
eventTargetURL:queueStatus.eventTargetUrl
237262
queueItToken:queueStatus.queueitToken];
238-
}
263+
}
239264
failure:^(NSError *error, NSString* errorMessage)
240265
{
241-
if (error.code >= 400 && error.code < 500)
242-
{
243-
[self.queueITUnavailableDelegate notifyQueueITUnavailable: errorMessage];
244-
}
245-
else
246-
{
247-
[self enqueueRetryMonitor];
248-
}
249-
}];
266+
if (error.code >= 400 && error.code < 500)
267+
{
268+
[self.queueITUnavailableDelegate notifyQueueITUnavailable: errorMessage];
269+
}
270+
else
271+
{
272+
[self enqueueRetryMonitor:enqueueToken enqueueKey:enqueueKey];
273+
}
274+
}];
250275
}
251276

252-
-(void)enqueueRetryMonitor
277+
-(void)enqueueRetryMonitor:(NSString*)enqueueToken
278+
enqueueKey:(NSString*)enqueueKey
253279
{
254280
if (self.deltaSec < MAX_RETRY_SEC)
255281
{
256-
[self tryEnqueue];
282+
[self tryEnqueue:enqueueToken enqueueKey:enqueueKey];
257283

258284
[NSThread sleepForTimeInterval:self.deltaSec];
259285
self.deltaSec = self.deltaSec * 2;
@@ -299,8 +325,16 @@ -(void) raiseQueueDisabled
299325
[self.queueDisabledDelegate notifyQueueDisabled];
300326
}
301327

328+
-(void) raiseSessionRestart
329+
{
330+
self.requestInProgress = NO;
331+
[self.cache clear];
332+
[self.queueSessionRestartDelegate notifySessionRestart];
333+
}
334+
302335
-(void) raiseViewClosed
303336
{
337+
self.requestInProgress = NO;
304338
[self.queueViewClosedDelegate notifyViewClosed];
305339
}
306340

QueueITLib/QueueITWKViewController.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
customerId:(nonnull NSString*)customerId
1111
eventId:(nonnull NSString*)eventId;
1212

13-
- (void)close: (void (^ __nullable)(void))completion;
13+
- (void)close:(void (^ __nullable)(void))completion;
1414

1515
- (BOOL)handleSpecialUrls:(nonnull NSURL*) url
1616
decisionHandler:(nonnull void (^)(WKNavigationActionPolicy))decisionHandler;
@@ -20,5 +20,4 @@
2020

2121
- (BOOL) isBlockedUrl:(nonnull NSURL*) destinationUrl;
2222

23-
@end
24-
23+
@end

QueueITLib/QueueITWKViewController.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ -(instancetype)initWithHost:(UIViewController *)host
3737
return self;
3838
}
3939

40-
- (void)close: (void (^ __nullable)(void))onComplete {
40+
- (void)close:(void (^ __nullable)(void))onComplete {
4141
[self.host dismissViewControllerAnimated:YES completion:^{
4242
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
4343
if(onComplete!=nil){
@@ -73,6 +73,12 @@ - (BOOL)handleSpecialUrls:(NSURL*) url
7373
}];
7474
decisionHandler(WKNavigationActionPolicyCancel);
7575
return true;
76+
} else if ([[url absoluteString] isEqualToString: QueueRestartSessionUrl]){
77+
[self close:^{
78+
[self.engine raiseSessionRestart];
79+
}];
80+
decisionHandler(WKNavigationActionPolicyCancel);
81+
return true;
7682
}
7783
return NO;
7884
}

QueueITLib/QueuePassedInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
@property (nonatomic, strong) NSString* queueitToken;
66

7-
-(instancetype)initWithQueueitToken: (NSString*) queueitToken;
7+
-(instancetype)initWithQueueitToken:(NSString*) queueitToken;
88

99
@end

QueueITLib/QueueService.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ typedef void (^QueueServiceFailure)(NSError *error, NSString* errorMessage);
1515
sdkVersion:(NSString*)sdkVersion
1616
layoutName:(NSString*)layoutName
1717
language:(NSString*)language
18+
enqueueToken:(NSString*)enqueueToken
19+
enqueueKey:(NSString*)enqueueKey
1820
success:(void(^)(QueueStatus* queueStatus))success
1921
failure:(QueueServiceFailure)failure;
2022

21-
2223
@end

0 commit comments

Comments
 (0)