Skip to content

Commit 702e038

Browse files
committed
Merged PR 2190: Added a internal handling of a *close* link
The SDK now handles special **close** links in the layouts. When a user clicks on `queueit://close` the webview would be closed. A method named close was added to both the WebView controller and the QueueITEngine. This method just dismisses the WebView screen. Related work items: #6789
1 parent 62bd28d commit 702e038

File tree

12 files changed

+91
-75
lines changed

12 files changed

+91
-75
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
QueueITLib.xcworkspace/xcuserdata/queut-it.xcuserdatad/xcdebugger/**
2+
QueueITLib.xcworkspace/xcuserdata

QueueITLib.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
1DE12FBE1B57F3DD00DD3BBE /* IOSUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IOSUtils.m; sourceTree = "<group>"; };
6969
1DE12FC01B57F42500DD3BBE /* QueueITEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QueueITEngine.h; sourceTree = "<group>"; };
7070
1DE12FC11B57F42500DD3BBE /* QueueITEngine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QueueITEngine.m; sourceTree = "<group>"; };
71+
90564B2E250A54AF009582C2 /* QueueConsts.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QueueConsts.h; sourceTree = "<group>"; };
7172
/* End PBXFileReference section */
7273

7374
/* Begin PBXFrameworksBuildPhase section */
@@ -125,6 +126,7 @@
125126
1DE12FB11B57F29A00DD3BBE /* Services */,
126127
1DE12FC01B57F42500DD3BBE /* QueueITEngine.h */,
127128
1DE12FC11B57F42500DD3BBE /* QueueITEngine.m */,
129+
90564B2E250A54AF009582C2 /* QueueConsts.h */,
128130
);
129131
path = QueueITLib;
130132
sourceTree = "<group>";

QueueITLib.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist

Lines changed: 0 additions & 8 deletions
This file was deleted.

QueueITLib.xcworkspace/xcshareddata/QueueITLib.xccheckout

Lines changed: 0 additions & 41 deletions
This file was deleted.
Binary file not shown.

QueueITLib/QueueConsts.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef QueueConsts_h
2+
#define QueueConsts_h
3+
4+
#define QueueCloseUrl @"queueit://close"
5+
6+
#endif

QueueITLib/QueueITEngine.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
#import <UIKit/UIKit.h>
22
#import "QueuePassedInfo.h"
3+
#import "QueueConsts.h"
34

45
@protocol QueuePassedDelegate;
56
@protocol QueueViewWillOpenDelegate;
67
@protocol QueueDisabledDelegate;
78
@protocol QueueITUnavailableDelegate;
89
@protocol QueueUserExitedDelegate;
10+
@protocol QueueViewClosedDelegate;
911

1012
@interface QueueITEngine : NSObject
1113
@property (nonatomic)id<QueuePassedDelegate> queuePassedDelegate;
1214
@property (nonatomic)id<QueueViewWillOpenDelegate> queueViewWillOpenDelegate;
1315
@property (nonatomic)id<QueueDisabledDelegate> queueDisabledDelegate;
1416
@property (nonatomic)id<QueueITUnavailableDelegate> queueITUnavailableDelegate;
1517
@property (nonatomic)id<QueueUserExitedDelegate> queueUserExitedDelegate;
18+
@property (nonatomic)id<QueueViewClosedDelegate> queueViewClosedDelegate;
1619
@property (nonatomic, strong)NSString* errorMessage;
1720

1821
typedef enum {
@@ -35,6 +38,8 @@ typedef enum {
3538
-(NSString*) errorTypeEnumToString:(QueueITRuntimeError)errorEnumVal;
3639
-(void)raiseUserExited;
3740
-(void)updateQueuePageUrl:(NSString*)queuePageUrl;
41+
-(void)raiseViewClosed;
42+
-(void)close: (void (^ __nullable)(void))onComplete;
3843

3944
@end
4045

@@ -57,3 +62,7 @@ typedef enum {
5762
@protocol QueueUserExitedDelegate <NSObject>
5863
-(void)notifyUserExited;
5964
@end
65+
66+
@protocol QueueViewClosedDelegate <NSObject>
67+
-(void)notifyViewClosed;
68+
@end

QueueITLib/QueueITEngine.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ @implementation QueueITEngine
2525

2626
static int MAX_RETRY_SEC = 10;
2727
static int INITIAL_WAIT_RETRY_SEC = 1;
28+
QueueITWKViewController *currentWebView;
2829

2930
-(instancetype)initWithHost:(UIViewController *)host customerId:(NSString*)customerId eventOrAliasId:(NSString*)eventOrAliasId layoutName:(NSString*)layoutName language:(NSString*)language
3031
{
@@ -45,6 +46,16 @@ -(instancetype)initWithHost:(UIViewController *)host customerId:(NSString*)custo
4546
return self;
4647
}
4748

49+
-(void)close: (void (^ __nullable)(void))onComplete
50+
{
51+
NSLog(@"Closing webview");
52+
if(currentWebView!=nil){
53+
dispatch_async(dispatch_get_main_queue(), ^{
54+
[currentWebView close: onComplete];
55+
});
56+
}
57+
}
58+
4859
-(void)setViewDelay:(int)delayInterval {
4960
self.delayInterval = delayInterval;
5061
}
@@ -132,6 +143,8 @@ -(void)showQueue:(NSString*)queueUrl targetUrl:(NSString*)targetUrl
132143
eventTargetUrl:targetUrl
133144
customerId:self.customerId
134145
eventId:self.eventId];
146+
currentWebView = queueWKVC;
147+
135148
if (@available(iOS 13.0, *)) {
136149
[queueWKVC setModalPresentationStyle: UIModalPresentationFullScreen];
137150
}
@@ -265,6 +278,11 @@ -(void) raiseQueueDisabled
265278
[self.queueDisabledDelegate notifyQueueDisabled];
266279
}
267280

281+
-(void) raiseViewClosed
282+
{
283+
[self.queueViewClosedDelegate notifyViewClosed];
284+
}
285+
268286
-(void) raiseUserExited
269287
{
270288
if (self.isInQueue) {

QueueITLib/QueueITWKViewController.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33

44
@interface QueueITWKViewController : UIViewController
55

6-
-(instancetype)initWithHost:(UIViewController *)host
7-
queueEngine:(QueueITEngine*) engine
8-
queueUrl:(NSString*)queueUrl
9-
eventTargetUrl:(NSString*)eventTargetUrl
10-
customerId:(NSString*)customerId
11-
eventId:(NSString*)eventId;
6+
-(instancetype _Nullable )initWithHost:(nonnull UIViewController *)host
7+
queueEngine:(nonnull QueueITEngine*) engine
8+
queueUrl:(nonnull NSString*)queueUrl
9+
eventTargetUrl:(nonnull NSString*)eventTargetUrl
10+
customerId:(nonnull NSString*)customerId
11+
eventId:(nonnull NSString*)eventId;
1212

13+
- (void)close: (void (^ __nullable)(void))completion;
14+
15+
- (BOOL)handleSpecialUrls:(nonnull NSURL*) url
16+
decisionHandler:(nonnull void (^)(WKNavigationActionPolicy))decisionHandler;
1317
@end
1418

QueueITLib/QueueITWKViewController.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,27 @@ -(instancetype)initWithHost:(UIViewController *)host
3737
return self;
3838
}
3939

40+
- (void)close: (void (^ __nullable)(void))onComplete {
41+
[self.host dismissViewControllerAnimated:YES completion:^{
42+
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
43+
if(onComplete!=nil){
44+
onComplete();
45+
}
46+
}];
47+
}
48+
49+
- (BOOL)handleSpecialUrls:(NSURL*) url
50+
decisionHandler:(nonnull void (^)(WKNavigationActionPolicy))decisionHandler {
51+
if([[url absoluteString] isEqualToString: QueueCloseUrl]){
52+
[self close: ^{
53+
[self.engine raiseViewClosed];
54+
}];
55+
decisionHandler(WKNavigationActionPolicyCancel);
56+
return true;
57+
}
58+
return NO;
59+
}
60+
4061
- (void)viewDidLoad {
4162
[super viewDidLoad];
4263

@@ -78,6 +99,10 @@ - (void)webView:(WKWebView*)webView decidePolicyForNavigationAction:(nonnull WKN
7899
if(urlString != nil && ![urlString isEqualToString:@"about:blank"]) {
79100
BOOL isQueueUrl = [self.queueUrl containsString:url.host];
80101
BOOL isNotFrame = [[[request URL] absoluteString] isEqualToString:[[request mainDocumentURL] absoluteString]];
102+
103+
if([self handleSpecialUrls:url decisionHandler:decisionHandler]){
104+
return;
105+
}
81106
if (isNotFrame) {
82107
if (isQueueUrl) {
83108
[self.engine updateQueuePageUrl:urlString];

0 commit comments

Comments
 (0)