Skip to content

Commit 9837090

Browse files
author
queue-it
committed
Preparing release 3.0.11
1 parent 31af26c commit 9837090

9 files changed

+89
-84
lines changed

QueueITLib/IOSUtils.m

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,29 @@ +(NSString*)getUserId{
1212
}
1313

1414
+(void)getUserAgent:(void (^)(NSString*))completionHandler{
15-
WKWebView* view = [[WKWebView alloc] initWithFrame:CGRectZero];
16-
[view evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id _Nullable userAgent, NSError * _Nullable error) {
17-
if (error == nil) {
18-
completionHandler(userAgent);
19-
}
20-
else {
21-
NSLog(@"Error getting userAgent");
22-
NSLog(@"%@", [error localizedDescription]);
23-
completionHandler(@"");
24-
}
25-
}];
26-
27-
webView = view;
15+
dispatch_async(dispatch_get_main_queue(), ^{
16+
WKWebView* view = [[WKWebView alloc] initWithFrame:CGRectZero];
17+
[view evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id _Nullable userAgent, NSError * _Nullable error) {
18+
if (error == nil) {
19+
completionHandler(userAgent);
20+
}
21+
else {
22+
completionHandler(@"");
23+
}
24+
webView = nil;
25+
}];
26+
webView = view;
27+
});
2828
}
2929

3030
+(NSString*)getLibraryVersion{
3131
NSDictionary *infoDictionary = [[NSBundle mainBundle]infoDictionary];
32-
32+
3333
NSString *libName = infoDictionary[(NSString *)kCFBundleNameKey];
3434
NSString * major = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
3535
NSString *minor = infoDictionary[(NSString*)kCFBundleVersionKey];
3636
NSString* libversion = [NSString stringWithFormat:@"%@-%@.%@", libName, major, minor];
37-
37+
3838
return libversion;
3939
}
4040

QueueITLib/QueueConsts.h

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

44
#define QueueCloseUrl @"queueit://close"
55
#define QueueRestartSessionUrl @"queueit://restartSession"
6-
#define SDKVersion @"iOS-3.0.10";
6+
#define SDKVersion @"iOS-3.0.11";
77

88
#endif

QueueITLib/QueueITEngine.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@
55

66
@protocol QueuePassedDelegate;
77
@protocol QueueViewWillOpenDelegate;
8+
@protocol QueueViewDidAppearDelegate;
89
@protocol QueueDisabledDelegate;
910
@protocol QueueITUnavailableDelegate;
1011
@protocol QueueUserExitedDelegate;
1112
@protocol QueueViewClosedDelegate;
1213
@protocol QueueSessionRestartDelegate;
1314

1415
@interface QueueITEngine : NSObject
15-
@property (nonatomic)id<QueuePassedDelegate> _Nonnull queuePassedDelegate;
16-
@property (nonatomic)id<QueueViewWillOpenDelegate> _Nullable queueViewWillOpenDelegate;
17-
@property (nonatomic)id<QueueDisabledDelegate> _Nonnull queueDisabledDelegate;
18-
@property (nonatomic)id<QueueITUnavailableDelegate> _Nullable queueITUnavailableDelegate;
19-
@property (nonatomic)id<QueueUserExitedDelegate> _Nullable queueUserExitedDelegate;
20-
@property (nonatomic)id<QueueViewClosedDelegate> _Nullable queueViewClosedDelegate;
21-
@property (nonatomic)id<QueueSessionRestartDelegate> _Nullable queueSessionRestartDelegate;
16+
@property (nonatomic, weak)id<QueuePassedDelegate> _Nullable queuePassedDelegate;
17+
@property (nonatomic, weak)id<QueueViewWillOpenDelegate> _Nullable queueViewWillOpenDelegate;
18+
@property (nonatomic, weak)id<QueueViewDidAppearDelegate> _Nullable queueViewDidAppearDelegate;
19+
@property (nonatomic, weak)id<QueueDisabledDelegate> _Nullable queueDisabledDelegate;
20+
@property (nonatomic, weak)id<QueueITUnavailableDelegate> _Nullable queueITUnavailableDelegate;
21+
@property (nonatomic, weak)id<QueueUserExitedDelegate> _Nullable queueUserExitedDelegate;
22+
@property (nonatomic, weak)id<QueueViewClosedDelegate> _Nullable queueViewClosedDelegate;
23+
@property (nonatomic, weak)id<QueueSessionRestartDelegate> _Nullable queueSessionRestartDelegate;
2224
@property (nonatomic, strong)NSString* _Nullable errorMessage;
2325

2426
typedef enum {
@@ -68,6 +70,10 @@ typedef enum {
6870
-(void)notifyQueueViewWillOpen;
6971
@end
7072

73+
@protocol QueueViewDidAppearDelegate <NSObject>
74+
-(void)notifyQueueViewDidAppear;
75+
@end
76+
7177
@protocol QueueDisabledDelegate <NSObject>
7278
-(void)notifyQueueDisabled:(QueueDisabledInfo* _Nullable) queueDisabledInfo;
7379
@end

QueueITLib/QueueITEngine.m

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@
88

99
@interface QueueITEngine()
1010
@property (nonatomic) Reachability *internetReachability;
11-
@property (nonatomic, strong)UIViewController* host;
12-
@property (nonatomic, strong)NSString* customerId;
13-
@property (nonatomic, strong)NSString* eventId;
14-
@property (nonatomic, strong)NSString* layoutName;
15-
@property (nonatomic, strong)NSString* language;
11+
@property (nonatomic, weak)UIViewController* host;
12+
@property (nonatomic, copy)NSString* customerId;
13+
@property (nonatomic, copy)NSString* eventId;
14+
@property (nonatomic, copy)NSString* layoutName;
15+
@property (nonatomic, copy)NSString* language;
1616
@property int delayInterval;
1717
@property bool isInQueue;
1818
@property bool requestInProgress;
1919
@property int queueUrlTtl;
20-
@property (nonatomic, strong)QueueCache* cache;
20+
@property (nonatomic, weak)QueueCache* cache;
2121
@property int deltaSec;
22+
@property (nonatomic, weak) QueueITWKViewController *currentWebView;
2223
@end
2324

2425
@implementation QueueITEngine
2526

2627
static int MAX_RETRY_SEC = 10;
2728
static int INITIAL_WAIT_RETRY_SEC = 1;
28-
QueueITWKViewController *currentWebView;
2929

3030
-(instancetype)initWithHost:(UIViewController *)host customerId:(NSString*)customerId eventOrAliasId:(NSString*)eventOrAliasId layoutName:(NSString*)layoutName language:(NSString*)language
3131
{
@@ -49,9 +49,9 @@ -(instancetype)initWithHost:(UIViewController *)host customerId:(NSString*)custo
4949
-(void)close:(void (^ __nullable)(void))onComplete
5050
{
5151
NSLog(@"Closing webview");
52-
if(currentWebView!=nil){
52+
if(self.currentWebView!=nil){
5353
dispatch_async(dispatch_get_main_queue(), ^{
54-
[currentWebView close: onComplete];
54+
[self.currentWebView close: onComplete];
5555
});
5656
}
5757
}
@@ -162,18 +162,22 @@ -(void)showQueue:(NSString*)queueUrl targetUrl:(NSString*)targetUrl
162162
eventTargetUrl:targetUrl
163163
customerId:self.customerId
164164
eventId:self.eventId];
165-
currentWebView = queueWKVC;
166-
167165
if (@available(iOS 13.0, *)) {
168166
[queueWKVC setModalPresentationStyle: UIModalPresentationFullScreen];
169167
}
170168
if (self.delayInterval > 0) {
171169
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(self.delayInterval * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
172-
[self.host presentViewController:queueWKVC animated:YES completion:nil];
170+
[self.host presentViewController:queueWKVC animated:YES completion:^{
171+
self.currentWebView = queueWKVC;
172+
[self raiseQueueViewDidAppear];
173+
}];
173174
});
174175
} else {
175176
dispatch_async(dispatch_get_main_queue(), ^{
176-
[self.host presentViewController:queueWKVC animated:YES completion:nil];
177+
[self.host presentViewController:queueWKVC animated:YES completion:^{
178+
self.currentWebView = queueWKVC;
179+
[self raiseQueueViewDidAppear];
180+
}];
177181
});
178182
}
179183
}
@@ -208,7 +212,8 @@ -(void)handleAppEnqueueResponse:(NSString*) queueId
208212
eventTargetURL:(NSString*) targetURL
209213
queueItToken:(NSString*) token {
210214
//SafetyNet
211-
if ([self isSafetyNet:queueId queueURL:queueURL]){
215+
if ([self isSafetyNet:queueId queueURL:queueURL])
216+
{
212217
self.requestInProgress = NO;
213218
[self raiseQueuePassed:token];
214219
return;
@@ -309,23 +314,26 @@ -(void) raiseQueuePassed:(NSString*) queueitToken
309314
[self.cache clear];
310315

311316
self.isInQueue = NO;
312-
317+
self.requestInProgress = NO;
313318
[self.queuePassedDelegate notifyYourTurn:queuePassedInfo];
314319
}
315320

316321

317322
-(void) raiseQueueViewWillOpen
318323
{
319-
self.isInQueue = YES;
320324
[self.queueViewWillOpenDelegate notifyQueueViewWillOpen];
321325
}
322326

327+
- (void)raiseQueueViewDidAppear
328+
{
329+
self.isInQueue = YES;
330+
[self.queueViewDidAppearDelegate notifyQueueViewDidAppear];
331+
}
332+
323333
-(void) raiseQueueDisabled:(NSString*) queueitToken
324334
{
325335
QueueDisabledInfo* queueDisabledInfo = [[QueueDisabledInfo alloc]initWithQueueitToken:queueitToken];
326-
327336
self.isInQueue = NO;
328-
329337
[self.queueDisabledDelegate notifyQueueDisabled:queueDisabledInfo];
330338
}
331339

QueueITLib/QueueITWKViewController.m

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ -(instancetype)initWithHost:(UIViewController *)host
3939

4040
- (void)close:(void (^ __nullable)(void))onComplete {
4141
[self.host dismissViewControllerAnimated:YES completion:^{
42-
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
4342
if(onComplete!=nil){
4443
onComplete();
4544
}
@@ -97,6 +96,8 @@ - (void)viewDidLoad {
9796
}
9897

9998
- (void)viewWillAppear:(BOOL)animated{
99+
[super viewWillAppear:animated];
100+
100101
self.spinner = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
101102
[self.spinner setColor:[UIColor grayColor]];
102103
[self.spinner startAnimating];
@@ -109,32 +110,36 @@ - (void)viewWillAppear:(BOOL)animated{
109110
[self.webView loadRequest:request];
110111
}
111112

113+
- (void)viewDidDisappear:(BOOL)animated
114+
{
115+
[super viewDidDisappear:animated];
116+
[self.webView removeFromSuperview];
117+
self.webView = nil;
118+
}
119+
112120
#pragma mark - WKNavigationDelegate
113121

114122
- (void)webView:(WKWebView*)webView decidePolicyForNavigationAction:(nonnull WKNavigationAction *)navigationAction decisionHandler:(nonnull void (^)(WKNavigationActionPolicy))decisionHandler{
115-
116123
if (!self.isQueuePassed) {
117124
NSURLRequest* request = navigationAction.request;
118125
NSString* urlString = [[request URL] absoluteString];
119126
NSString* targetUrlString = self.eventTargetUrl;
120-
NSLog(@"request Url: %@", urlString);
121-
NSLog(@"target Url: %@", targetUrlString);
122127
if (urlString != nil) {
123128
NSURL* url = [NSURL URLWithString:urlString];
124129
NSURL* targetUrl = [NSURL URLWithString:targetUrlString];
125130
if(urlString != nil && ![urlString isEqualToString:@"about:blank"]) {
126131
BOOL isQueueUrl = [self.queueUrl containsString:url.host];
127132
BOOL isNotFrame = [[[request URL] absoluteString] isEqualToString:[[request mainDocumentURL] absoluteString]];
128-
133+
129134
if([self handleSpecialUrls:url decisionHandler:decisionHandler]){
130135
return;
131136
}
132-
137+
133138
if([self isBlockedUrl: url]){
134139
decisionHandler(WKNavigationActionPolicyCancel);
135140
return;
136141
}
137-
142+
138143
if (isNotFrame) {
139144
if (isQueueUrl) {
140145
[self.engine updateQueuePageUrl:urlString];
@@ -145,7 +150,6 @@ - (void)webView:(WKWebView*)webView decidePolicyForNavigationAction:(nonnull WKN
145150
NSString* queueitToken = [self extractQueueToken:url.absoluteString];
146151
[self.engine raiseQueuePassed:queueitToken];
147152
[self.host dismissViewControllerAnimated:YES completion:^{
148-
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
149153
}];
150154
decisionHandler(WKNavigationActionPolicyCancel);
151155
return;
@@ -154,22 +158,23 @@ - (void)webView:(WKWebView*)webView decidePolicyForNavigationAction:(nonnull WKN
154158
if (navigationAction.navigationType == WKNavigationTypeLinkActivated && !isQueueUrl) {
155159
if (@available(iOS 10, *)){
156160
[[UIApplication sharedApplication] openURL:[request URL] options:@{} completionHandler:^(BOOL success){
157-
if (success){
158-
NSLog(@"Opened %@",urlString);
159-
}
161+
160162
}];
161163
}
162164
else {
165+
#pragma GCC diagnostic push
166+
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
163167
[[UIApplication sharedApplication] openURL:[request URL]];
168+
#pragma GCC diagnostic pop
164169
}
165-
170+
166171
decisionHandler(WKNavigationActionPolicyCancel);
167172
return;
168173
}
169174
}
170175
}
171176
}
172-
177+
173178
decisionHandler(WKNavigationActionPolicyAllow);
174179
}
175180

@@ -186,18 +191,15 @@ - (NSString*)extractQueueToken:(NSString*) url {
186191
}
187192

188193
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
189-
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
190194
}
191195

192196
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
193-
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
194-
195197
[self.spinner stopAnimating];
196198
if (![self.webView isLoading])
197199
{
198200
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil];
199201
}
200-
202+
201203
// Check if user exitted through the default exit link and notify the engine
202204
[self.webView evaluateJavaScript:JAVASCRIPT_GET_BODY_CLASSES completionHandler:^(id result, NSError* error){
203205
if (error != nil) {

QueueITLib/QueueService_NSURLConnectionRequest.m

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ - (instancetype)initWithRequest:(NSURLRequest *)request
3131
self.failureCallback = failure;
3232
self.uniqueIdentifier = [[NSUUID UUID] UUIDString];
3333
self.delegate = delegate;
34-
34+
3535
[self initiateRequest];
3636
}
37-
37+
3838
return self;
3939
}
4040

@@ -43,7 +43,10 @@ - (void)initiateRequest
4343
self.response = nil;
4444
self.data = [NSMutableData data];
4545
self.actualStatusCode = NSNotFound;
46+
#pragma GCC diagnostic push
47+
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
4648
self.connection = [[NSURLConnection alloc] initWithRequest:self.request delegate:self];
49+
#pragma GCC diagnostic pop
4750
}
4851

4952
#pragma mark - NSURLConnectionDelegate
@@ -53,7 +56,7 @@ - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)err
5356
dispatch_async(dispatch_get_main_queue(), ^{
5457
self.failureCallback(error, @"Unexpected failure occured.");
5558
});
56-
59+
5760
[self.delegate requestDidComplete:self];
5861
}
5962

@@ -80,7 +83,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
8083
}
8184
else {
8285
NSString *message = [NSString stringWithFormat:@"Unexpected response code: %li", (long)self.actualStatusCode];
83-
86+
8487
if (self.actualStatusCode >= 400 && self.actualStatusCode < 500)
8588
{
8689
message = [NSString stringWithCString:[self.data bytes] encoding:NSASCIIStringEncoding];
@@ -98,16 +101,16 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
98101
}
99102
}
100103
}
101-
104+
102105
NSError *error = [NSError errorWithDomain:@"QueueService"
103106
code:self.actualStatusCode
104107
userInfo:@{ NSLocalizedDescriptionKey: message }];
105-
108+
106109
dispatch_async(dispatch_get_main_queue(), ^{
107110
self.failureCallback(error, message);
108111
});
109112
}
110-
113+
111114
[self.delegate requestDidComplete:self];
112115
}
113116

@@ -123,7 +126,7 @@ - (BOOL)hasExpectedStatusCode
123126
if (self.actualStatusCode != NSNotFound) {
124127
return self.expectedStatusCode == self.actualStatusCode;
125128
}
126-
129+
127130
return NO;
128131
}
129132

0 commit comments

Comments
 (0)