Skip to content

Commit

Permalink
Preparing release 3.0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
queue-it committed Apr 28, 2022
1 parent 31af26c commit 9837090
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 84 deletions.
30 changes: 15 additions & 15 deletions QueueITLib/IOSUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@ +(NSString*)getUserId{
}

+(void)getUserAgent:(void (^)(NSString*))completionHandler{
WKWebView* view = [[WKWebView alloc] initWithFrame:CGRectZero];
[view evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id _Nullable userAgent, NSError * _Nullable error) {
if (error == nil) {
completionHandler(userAgent);
}
else {
NSLog(@"Error getting userAgent");
NSLog(@"%@", [error localizedDescription]);
completionHandler(@"");
}
}];

webView = view;
dispatch_async(dispatch_get_main_queue(), ^{
WKWebView* view = [[WKWebView alloc] initWithFrame:CGRectZero];
[view evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id _Nullable userAgent, NSError * _Nullable error) {
if (error == nil) {
completionHandler(userAgent);
}
else {
completionHandler(@"");
}
webView = nil;
}];
webView = view;
});
}

+(NSString*)getLibraryVersion{
NSDictionary *infoDictionary = [[NSBundle mainBundle]infoDictionary];

NSString *libName = infoDictionary[(NSString *)kCFBundleNameKey];
NSString * major = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
NSString *minor = infoDictionary[(NSString*)kCFBundleVersionKey];
NSString* libversion = [NSString stringWithFormat:@"%@-%@.%@", libName, major, minor];

return libversion;
}

Expand Down
2 changes: 1 addition & 1 deletion QueueITLib/QueueConsts.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

#define QueueCloseUrl @"queueit://close"
#define QueueRestartSessionUrl @"queueit://restartSession"
#define SDKVersion @"iOS-3.0.10";
#define SDKVersion @"iOS-3.0.11";

#endif
20 changes: 13 additions & 7 deletions QueueITLib/QueueITEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@

@protocol QueuePassedDelegate;
@protocol QueueViewWillOpenDelegate;
@protocol QueueViewDidAppearDelegate;
@protocol QueueDisabledDelegate;
@protocol QueueITUnavailableDelegate;
@protocol QueueUserExitedDelegate;
@protocol QueueViewClosedDelegate;
@protocol QueueSessionRestartDelegate;

@interface QueueITEngine : NSObject
@property (nonatomic)id<QueuePassedDelegate> _Nonnull queuePassedDelegate;
@property (nonatomic)id<QueueViewWillOpenDelegate> _Nullable queueViewWillOpenDelegate;
@property (nonatomic)id<QueueDisabledDelegate> _Nonnull queueDisabledDelegate;
@property (nonatomic)id<QueueITUnavailableDelegate> _Nullable queueITUnavailableDelegate;
@property (nonatomic)id<QueueUserExitedDelegate> _Nullable queueUserExitedDelegate;
@property (nonatomic)id<QueueViewClosedDelegate> _Nullable queueViewClosedDelegate;
@property (nonatomic)id<QueueSessionRestartDelegate> _Nullable queueSessionRestartDelegate;
@property (nonatomic, weak)id<QueuePassedDelegate> _Nullable queuePassedDelegate;
@property (nonatomic, weak)id<QueueViewWillOpenDelegate> _Nullable queueViewWillOpenDelegate;
@property (nonatomic, weak)id<QueueViewDidAppearDelegate> _Nullable queueViewDidAppearDelegate;
@property (nonatomic, weak)id<QueueDisabledDelegate> _Nullable queueDisabledDelegate;
@property (nonatomic, weak)id<QueueITUnavailableDelegate> _Nullable queueITUnavailableDelegate;
@property (nonatomic, weak)id<QueueUserExitedDelegate> _Nullable queueUserExitedDelegate;
@property (nonatomic, weak)id<QueueViewClosedDelegate> _Nullable queueViewClosedDelegate;
@property (nonatomic, weak)id<QueueSessionRestartDelegate> _Nullable queueSessionRestartDelegate;
@property (nonatomic, strong)NSString* _Nullable errorMessage;

typedef enum {
Expand Down Expand Up @@ -68,6 +70,10 @@ typedef enum {
-(void)notifyQueueViewWillOpen;
@end

@protocol QueueViewDidAppearDelegate <NSObject>
-(void)notifyQueueViewDidAppear;
@end

@protocol QueueDisabledDelegate <NSObject>
-(void)notifyQueueDisabled:(QueueDisabledInfo* _Nullable) queueDisabledInfo;
@end
Expand Down
44 changes: 26 additions & 18 deletions QueueITLib/QueueITEngine.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@

@interface QueueITEngine()
@property (nonatomic) Reachability *internetReachability;
@property (nonatomic, strong)UIViewController* host;
@property (nonatomic, strong)NSString* customerId;
@property (nonatomic, strong)NSString* eventId;
@property (nonatomic, strong)NSString* layoutName;
@property (nonatomic, strong)NSString* language;
@property (nonatomic, weak)UIViewController* host;
@property (nonatomic, copy)NSString* customerId;
@property (nonatomic, copy)NSString* eventId;
@property (nonatomic, copy)NSString* layoutName;
@property (nonatomic, copy)NSString* language;
@property int delayInterval;
@property bool isInQueue;
@property bool requestInProgress;
@property int queueUrlTtl;
@property (nonatomic, strong)QueueCache* cache;
@property (nonatomic, weak)QueueCache* cache;
@property int deltaSec;
@property (nonatomic, weak) QueueITWKViewController *currentWebView;
@end

@implementation QueueITEngine

static int MAX_RETRY_SEC = 10;
static int INITIAL_WAIT_RETRY_SEC = 1;
QueueITWKViewController *currentWebView;

-(instancetype)initWithHost:(UIViewController *)host customerId:(NSString*)customerId eventOrAliasId:(NSString*)eventOrAliasId layoutName:(NSString*)layoutName language:(NSString*)language
{
Expand All @@ -49,9 +49,9 @@ -(instancetype)initWithHost:(UIViewController *)host customerId:(NSString*)custo
-(void)close:(void (^ __nullable)(void))onComplete
{
NSLog(@"Closing webview");
if(currentWebView!=nil){
if(self.currentWebView!=nil){
dispatch_async(dispatch_get_main_queue(), ^{
[currentWebView close: onComplete];
[self.currentWebView close: onComplete];
});
}
}
Expand Down Expand Up @@ -162,18 +162,22 @@ -(void)showQueue:(NSString*)queueUrl targetUrl:(NSString*)targetUrl
eventTargetUrl:targetUrl
customerId:self.customerId
eventId:self.eventId];
currentWebView = queueWKVC;

if (@available(iOS 13.0, *)) {
[queueWKVC setModalPresentationStyle: UIModalPresentationFullScreen];
}
if (self.delayInterval > 0) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(self.delayInterval * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.host presentViewController:queueWKVC animated:YES completion:nil];
[self.host presentViewController:queueWKVC animated:YES completion:^{
self.currentWebView = queueWKVC;
[self raiseQueueViewDidAppear];
}];
});
} else {
dispatch_async(dispatch_get_main_queue(), ^{
[self.host presentViewController:queueWKVC animated:YES completion:nil];
[self.host presentViewController:queueWKVC animated:YES completion:^{
self.currentWebView = queueWKVC;
[self raiseQueueViewDidAppear];
}];
});
}
}
Expand Down Expand Up @@ -208,7 +212,8 @@ -(void)handleAppEnqueueResponse:(NSString*) queueId
eventTargetURL:(NSString*) targetURL
queueItToken:(NSString*) token {
//SafetyNet
if ([self isSafetyNet:queueId queueURL:queueURL]){
if ([self isSafetyNet:queueId queueURL:queueURL])
{
self.requestInProgress = NO;
[self raiseQueuePassed:token];
return;
Expand Down Expand Up @@ -309,23 +314,26 @@ -(void) raiseQueuePassed:(NSString*) queueitToken
[self.cache clear];

self.isInQueue = NO;

self.requestInProgress = NO;
[self.queuePassedDelegate notifyYourTurn:queuePassedInfo];
}


-(void) raiseQueueViewWillOpen
{
self.isInQueue = YES;
[self.queueViewWillOpenDelegate notifyQueueViewWillOpen];
}

- (void)raiseQueueViewDidAppear
{
self.isInQueue = YES;
[self.queueViewDidAppearDelegate notifyQueueViewDidAppear];
}

-(void) raiseQueueDisabled:(NSString*) queueitToken
{
QueueDisabledInfo* queueDisabledInfo = [[QueueDisabledInfo alloc]initWithQueueitToken:queueitToken];

self.isInQueue = NO;

[self.queueDisabledDelegate notifyQueueDisabled:queueDisabledInfo];
}

Expand Down
36 changes: 19 additions & 17 deletions QueueITLib/QueueITWKViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ -(instancetype)initWithHost:(UIViewController *)host

- (void)close:(void (^ __nullable)(void))onComplete {
[self.host dismissViewControllerAnimated:YES completion:^{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
if(onComplete!=nil){
onComplete();
}
Expand Down Expand Up @@ -97,6 +96,8 @@ - (void)viewDidLoad {
}

- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];

self.spinner = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
[self.spinner setColor:[UIColor grayColor]];
[self.spinner startAnimating];
Expand All @@ -109,32 +110,36 @@ - (void)viewWillAppear:(BOOL)animated{
[self.webView loadRequest:request];
}

- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[self.webView removeFromSuperview];
self.webView = nil;
}

#pragma mark - WKNavigationDelegate

- (void)webView:(WKWebView*)webView decidePolicyForNavigationAction:(nonnull WKNavigationAction *)navigationAction decisionHandler:(nonnull void (^)(WKNavigationActionPolicy))decisionHandler{

if (!self.isQueuePassed) {
NSURLRequest* request = navigationAction.request;
NSString* urlString = [[request URL] absoluteString];
NSString* targetUrlString = self.eventTargetUrl;
NSLog(@"request Url: %@", urlString);
NSLog(@"target Url: %@", targetUrlString);
if (urlString != nil) {
NSURL* url = [NSURL URLWithString:urlString];
NSURL* targetUrl = [NSURL URLWithString:targetUrlString];
if(urlString != nil && ![urlString isEqualToString:@"about:blank"]) {
BOOL isQueueUrl = [self.queueUrl containsString:url.host];
BOOL isNotFrame = [[[request URL] absoluteString] isEqualToString:[[request mainDocumentURL] absoluteString]];

if([self handleSpecialUrls:url decisionHandler:decisionHandler]){
return;
}

if([self isBlockedUrl: url]){
decisionHandler(WKNavigationActionPolicyCancel);
return;
}

if (isNotFrame) {
if (isQueueUrl) {
[self.engine updateQueuePageUrl:urlString];
Expand All @@ -145,7 +150,6 @@ - (void)webView:(WKWebView*)webView decidePolicyForNavigationAction:(nonnull WKN
NSString* queueitToken = [self extractQueueToken:url.absoluteString];
[self.engine raiseQueuePassed:queueitToken];
[self.host dismissViewControllerAnimated:YES completion:^{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}];
decisionHandler(WKNavigationActionPolicyCancel);
return;
Expand All @@ -154,22 +158,23 @@ - (void)webView:(WKWebView*)webView decidePolicyForNavigationAction:(nonnull WKN
if (navigationAction.navigationType == WKNavigationTypeLinkActivated && !isQueueUrl) {
if (@available(iOS 10, *)){
[[UIApplication sharedApplication] openURL:[request URL] options:@{} completionHandler:^(BOOL success){
if (success){
NSLog(@"Opened %@",urlString);
}

}];
}
else {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[UIApplication sharedApplication] openURL:[request URL]];
#pragma GCC diagnostic pop
}

decisionHandler(WKNavigationActionPolicyCancel);
return;
}
}
}
}

decisionHandler(WKNavigationActionPolicyAllow);
}

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

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

- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

[self.spinner stopAnimating];
if (![self.webView isLoading])
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil];
}

// Check if user exitted through the default exit link and notify the engine
[self.webView evaluateJavaScript:JAVASCRIPT_GET_BODY_CLASSES completionHandler:^(id result, NSError* error){
if (error != nil) {
Expand Down
19 changes: 11 additions & 8 deletions QueueITLib/QueueService_NSURLConnectionRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ - (instancetype)initWithRequest:(NSURLRequest *)request
self.failureCallback = failure;
self.uniqueIdentifier = [[NSUUID UUID] UUIDString];
self.delegate = delegate;

[self initiateRequest];
}

return self;
}

Expand All @@ -43,7 +43,10 @@ - (void)initiateRequest
self.response = nil;
self.data = [NSMutableData data];
self.actualStatusCode = NSNotFound;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
self.connection = [[NSURLConnection alloc] initWithRequest:self.request delegate:self];
#pragma GCC diagnostic pop
}

#pragma mark - NSURLConnectionDelegate
Expand All @@ -53,7 +56,7 @@ - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)err
dispatch_async(dispatch_get_main_queue(), ^{
self.failureCallback(error, @"Unexpected failure occured.");
});

[self.delegate requestDidComplete:self];
}

Expand All @@ -80,7 +83,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
}
else {
NSString *message = [NSString stringWithFormat:@"Unexpected response code: %li", (long)self.actualStatusCode];

if (self.actualStatusCode >= 400 && self.actualStatusCode < 500)
{
message = [NSString stringWithCString:[self.data bytes] encoding:NSASCIIStringEncoding];
Expand All @@ -98,16 +101,16 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
}
}
}

NSError *error = [NSError errorWithDomain:@"QueueService"
code:self.actualStatusCode
userInfo:@{ NSLocalizedDescriptionKey: message }];

dispatch_async(dispatch_get_main_queue(), ^{
self.failureCallback(error, message);
});
}

[self.delegate requestDidComplete:self];
}

Expand All @@ -123,7 +126,7 @@ - (BOOL)hasExpectedStatusCode
if (self.actualStatusCode != NSNotFound) {
return self.expectedStatusCode == self.actualStatusCode;
}

return NO;
}

Expand Down
Loading

0 comments on commit 9837090

Please sign in to comment.