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.

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];

QueueITLibrary.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Pod::Spec.new do |s|
22
s.name = "QueueITLibrary"
3-
s.version = "3.0.1"
3+
s.version = "3.0.3"
44
s.summary = "Library for integrating Queue-it into an iOS app using web uI"
55
s.homepage = "https://github.com/queueit/ios-webui-sdk"
66
s.license = 'MIT'
77
s.authors = { 'Queue-It' => 'https://queue-it.com' }
88
s.platform = :ios, '9.3'
9-
s.source = { :git => 'https://github.com/queueit/ios-webui-sdk.git', :tag => '3.0.1' }
9+
s.source = { :git => 'https://github.com/queueit/ios-webui-sdk.git', :tag => '3.0.3' }
1010
s.requires_arc = true
1111
s.source_files = "QueueITLib/*.{h,m}"
1212
end

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Library for integrating Queue-It's virtual waiting room into an iOS app that is
66

77
## Installation
88

9-
Before starting please download the whitepaper **Mobile App Integration** from GO Queue-it Platform.
9+
Before starting please download the whitepaper **Mobile App Integration** from GO Queue-it Platform.
1010
This whitepaper contains the needed information to perform a successful integration.
1111

1212
### Requirements
@@ -34,7 +34,7 @@ platform :ios, '9.3'
3434
use_frameworks!
3535

3636
target '<Your Target Name>' do
37-
pod 'QueueITLibrary', '~> 3.0.0'
37+
pod 'QueueITLibrary', '~> 3.0.3'
3838
end
3939
```
4040

@@ -54,7 +54,7 @@ In this example we have a `UITableViewController` that we want to protect using
5454
#import <UIKit/UIKit.h>
5555
#import "QueueITEngine.h"
5656

57-
@interface TopsTableViewController : UITableViewController<QueuePassedDelegate, QueueViewWillOpenDelegate, QueueDisabledDelegate, QueueITUnavailableDelegate>
57+
@interface TopsTableViewController : UITableViewController<QueuePassedDelegate, QueueViewWillOpenDelegate, QueueDisabledDelegate, QueueITUnavailableDelegate, QueueViewClosedDelegate>
5858
-(void)initAndRunQueueIt;
5959
@end
6060
```
@@ -70,18 +70,20 @@ The implementation of the example controller looks like follows:
7070
NSString* eventOrAliasId = @"yourEventId"; // Required
7171
NSString* layoutName = @"yourLayoutName"; // Optional (pass nil if no layout specified)
7272
NSString* language = @"en-US"; // Optional (pass nil if no language specified)
73-
73+
7474
self.engine = [[QueueITEngine alloc]initWithHost:self customerId:customerId eventOrAliasId:eventOrAliasId layoutName:layoutName language:language];
7575
[self.engine setViewDelay:5]; // Optional delay parameter you can specify (in case you want to inject some animation before Queue-It UIWebView or WKWebView will appear
7676
self.engine.queuePassedDelegate = self; // Invoked once the user is passed the queue
7777
self.engine.queueViewWillOpenDelegate = self; // Invoked to notify that Queue-It UIWebView or WKWebview will open
7878
self.engine.queueDisabledDelegate = self; // Invoked to notify that queue is disabled
7979
self.engine.queueITUnavailableDelegate = self; // Invoked in case QueueIT is unavailable (500 errors)
8080
self.engine.queueUserExitedDelegate = self; // Invoked when user chooses to leave the queue
81+
self.engine.queueViewClosedDelegate = self; // Invoked after the WebView is closed
8182
8283
NSError* error = nil;
8384
BOOL success = [self.engine run:&error];
84-
if (!success) { if ([error code] == NetworkUnavailable) {
85+
if (!success) {
86+
if ([error code] == NetworkUnavailable) {
8587
// Thrown when Queue-It detects no internet connectivity
8688
NSLog(@"%ld", (long)[error code]);
8789
NSLog(@"Network unavailable was caught in DetailsViewController");
@@ -97,40 +99,38 @@ The implementation of the example controller looks like follows:
9799
}
98100
99101
// This callback will be triggered when the user has been through the queue.
100-
// Here you should store session information, so user will only be sent to queue again if the session has timed out.
101-
-(void) notifyYourTurn: (QueuePassedInfo*) queuePassedInfo {
102+
// Here you should store session information, so user will only be sent to queue again if the session has timed out.
103+
-(void) notifyYourTurn: (QueuePassedInfo*) queuePassedInfo {
102104
NSLog(@"You have been through the queue");
103105
NSLog(@"QUEUE TOKEN: %@", queuePassedInfo.queueitToken);
104106
}
105107
106108
// This callback will be triggered just before the webview (hosting the queue page) will be shown.
107-
// Here you can change some relevant UI elements.
108-
-(void) notifyQueueViewWillOpen {
109+
// Here you can change some relevant UI elements.
110+
-(void) notifyQueueViewWillOpen {
109111
NSLog(@"Queue will open");
110112
}
111113
112114
// This callback will be triggered when the queue used (event alias ID) is in the 'disabled' state.
113-
// Most likely the application should still function, but the queue's 'disabled' state can be changed at any time,
115+
// Most likely the application should still function, but the queue's 'disabled' state can be changed at any time,
114116
// so session handling is important.
115-
-(void) notifyQueueDisabled {
117+
-(void) notifyQueueDisabled {
116118
NSLog(@"Queue is disabled");
117119
}
118120
119121
// This callback will be triggered when the mobile application can't reach Queue-it's servers.
120122
// Most likely because the mobile device has no internet connection.
121123
// Here you decide if the application should function or not now that is has no queue-it protection.
122-
-(void) notifyQueueITUnavailable: (NSString*) errorMessage {
124+
-(void) notifyQueueITUnavailable: (NSString*) errorMessage {
123125
NSLog(@"QueueIT is currently unavailable");
124126
}
125127
126-
// This callback will be triggered when user has been on the queue page via the webview
127-
// but decided to click the 'leave the queue' button/link.
128-
// Most likely you would want to clear any session and refresh so user will be joining the queue again.
129-
// We do recommend you to hide 'leave queue' on your queue page so this callback should not be handled in most cases.
130-
-(void) notifyUserExited {
131-
NSLog(@"User has left the queue");
128+
// This callback will be triggered after a user clicks a close link in the layout and the WebView closes.
129+
-(void)notifyViewClosed {
130+
NSLog(@"The queue view was closed.")
132131
}
133132
```
133+
134134
As the App developer you must manage the state (whether user was previously queued up or not) inside the apps storage.
135135
After you have received the "notifyYourTurn callback", the app must remember this, possibly with a date / time expiration.
136136
When the user goes to the next page - you check this state, and only call QueueITEngine.run in the case where the user did not previously queue up.

0 commit comments

Comments
 (0)