From ddc14c91dfca057a03793ab7339ee3da033370b2 Mon Sep 17 00:00:00 2001 From: Hassan Shahbazi Date: Thu, 26 Mar 2020 22:43:00 +0200 Subject: [PATCH 1/5] resolve issue --- .../ChatViewController/NINChatViewController.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/NinchatSDK/UI/ViewControllers/ChatViewController/NINChatViewController.m b/NinchatSDK/UI/ViewControllers/ChatViewController/NINChatViewController.m index 2d18d51..c44b27b 100644 --- a/NinchatSDK/UI/ViewControllers/ChatViewController/NINChatViewController.m +++ b/NinchatSDK/UI/ViewControllers/ChatViewController/NINChatViewController.m @@ -952,7 +952,12 @@ -(void) viewDidLoad { fetchNotification(kNINChannelClosedNotification, ^BOOL(NSNotification* notification) { [weakSelf stopObserverChatEvents]; [weakSelf disableInputControls]; - + + /// Ending the conversation must remove the video + /// As described in https://github.com/somia/ninchat-sdk-ios/issues/105 + [weakSelf disconnectWebRTC]; + [weakSelf adjustConstraintsForSize:weakSelf.view.bounds.size animate:YES]; + return YES; }); From 6d139ce32dffa7653439e6f590accad8392f21f0 Mon Sep 17 00:00:00 2001 From: Hassan Shahbazi Date: Sun, 29 Mar 2020 16:51:58 +0300 Subject: [PATCH 2/5] add scenarios for closed queues (#108) --- .../SessionManager/NINSessionManager.m | 9 ++- NinchatSDK/UI/Chat.storyboard | 16 +++++- .../InitialView/NINInitialViewController.m | 56 ++++++++++++++++--- .../QueueView/NINQueueViewController.m | 23 +++++--- NinchatSDK/Utils/Entities/NINQueue.h | 3 +- NinchatSDK/Utils/Entities/NINQueue.m | 4 +- 6 files changed, 92 insertions(+), 19 deletions(-) diff --git a/NinchatSDK/ManagersAndServices/SessionManager/NINSessionManager.m b/NinchatSDK/ManagersAndServices/SessionManager/NINSessionManager.m index 8cb6105..787f34e 100644 --- a/NinchatSDK/ManagersAndServices/SessionManager/NINSessionManager.m +++ b/NinchatSDK/ManagersAndServices/SessionManager/NINSessionManager.m @@ -195,7 +195,14 @@ -(void) realmQueuesFound:(NINLowLevelClientProps*)params { return; } - [_queues addObject:[NINQueue queueWithId:queueId andName:queueName]]; + BOOL isClosed; + [queueAttrs getBool:@"closed" val:&isClosed error:&error]; + if (error != nil) { + postNotification(kActionNotification, @{@"action_id": @(actionId), @"error": error}); + return; + } + + [_queues addObject:[NINQueue queueWithId:queueId andName:queueName isClosed:isClosed]]; } // Form the list of audience queues; if audienceQueues is specified in siteConfig, we use those; diff --git a/NinchatSDK/UI/Chat.storyboard b/NinchatSDK/UI/Chat.storyboard index 4042202..2077a7a 100644 --- a/NinchatSDK/UI/Chat.storyboard +++ b/NinchatSDK/UI/Chat.storyboard @@ -1,9 +1,9 @@ - + - + @@ -765,15 +765,26 @@ you are next. + + + + + + + + + + + @@ -829,6 +840,7 @@ you are next. + diff --git a/NinchatSDK/UI/ViewControllers/InitialView/NINInitialViewController.m b/NinchatSDK/UI/ViewControllers/InitialView/NINInitialViewController.m index 773e523..b85f578 100644 --- a/NinchatSDK/UI/ViewControllers/InitialView/NINInitialViewController.m +++ b/NinchatSDK/UI/ViewControllers/InitialView/NINInitialViewController.m @@ -18,6 +18,8 @@ // UI strings static NSString* const kJoinQueueText = @"Join audience queue {{audienceQueue.queue_attrs.name}}"; +static NSString* const kJoinClosedQueueText = @"Join audience queue {{audienceQueue.queue_attrs.name}} (Closed)"; +static NSString* const kNoQueueText = @"noQueuesText"; static NSString* const kCloseWindowText = @"Close window"; // Segue id to open queue view @@ -31,6 +33,7 @@ @interface NINInitialViewController () @property (nonatomic, strong) IBOutlet UIStackView* queueButtonsStackView; @property (nonatomic, strong) IBOutlet UIButton* closeWindowButton; @property (nonatomic, strong) IBOutlet UITextView* motdTextView; +@property (nonatomic, strong) IBOutlet UITextView* noQueueTextView; @end @@ -107,15 +110,40 @@ -(void) viewDidAppear:(BOOL)animated { } } +/// The function determines if there is at least one open queue to join +/// According to https://github.com/somia/ninchat-sdk-ios/issues/68 +- (BOOL) canJoinAtLeastOneQueue { + for (NINQueue *queue in self.sessionManager.audienceQueues) { + if (!queue.isClosed) { + return YES; + } + } + return NO; +} + +- (NSArray*) queueList { + NSMutableArray *list = [NSMutableArray new]; + for (NINQueue *queue in self.sessionManager.audienceQueues) { + if (!queue.isClosed) { + [list addObject:queue]; + } + } + return list; +} + -(void) createQueueButtons { const NSInteger maxButtons = 3; + [self.queueButtonsStackView setHidden:NO]; + [self.noQueueTextView setHidden:YES]; + // Remote any existing buttons in the stack view for (UIView* view in self.queueButtonsStackView.subviews) { [view removeFromSuperview]; } - NSInteger numButtons = MIN(maxButtons, self.sessionManager.audienceQueues.count); + NSArray* queues = [self queueList]; + NSInteger numButtons = MIN(maxButtons, queues.count); CGFloat buttonHeight = (numButtons > 2) ? 40.0 : 60.0; UIColor* defaultBgColor = [UIColor colorWithRed:73.0/255 green:172.0/255 blue:253.0/255 alpha:1]; @@ -124,8 +152,8 @@ -(void) createQueueButtons { __weak typeof(self) weakSelf = self; - for (NSInteger i = 0; i < numButtons; i++) { - NINQueue* queue = self.sessionManager.audienceQueues[i]; + for (NSUInteger i = 0; i < numButtons; i++) { + NINQueue* queue = queues[i]; UIButton* button = [UIButton buttonWithPressedCallback:^{ [weakSelf performSegueWithIdentifier:kSegueIdInitialToQueue sender:queue]; }]; @@ -136,19 +164,29 @@ -(void) createQueueButtons { button.layer.cornerRadius = buttonHeight / 2; button.backgroundColor = defaultBgColor; [button setTitleColor:defaultTextColor forState:UIControlStateNormal]; - [button setTitle:[self.sessionManager translation:kJoinQueueText formatParams:@{@"audienceQueue.queue_attrs.name": queue.name}] forState:UIControlStateNormal]; [button overrideAssetsWithSession:self.sessionManager.ninchatSession isPrimaryButton:YES]; + // Check if the queue is open to join, according to https://github.com/somia/ninchat-sdk-ios/issues/68 + [button setEnabled:!queue.isClosed]; + [button setAlpha: (queue.isClosed) ? 0.5 : 1.0]; + [button setTitle:[self.sessionManager translation:(queue.isClosed) ? kJoinClosedQueueText : kJoinQueueText formatParams:@{@"audienceQueue.queue_attrs.name": queue.name}] forState:UIControlStateNormal]; + // Add the button to the stack view [self.queueButtonsStackView addArrangedSubview:button]; // Set button height via constraint [constraints addObject:[button.heightAnchor constraintEqualToConstant:buttonHeight]]; } - [NSLayoutConstraint activateConstraints:constraints]; } +- (void) createNoQueueText { + [self.queueButtonsStackView setHidden:YES]; + [self.noQueueTextView setHidden:NO]; + + [self.noQueueTextView setFormattedText:[self.sessionManager.siteConfiguration valueForKey:kNoQueueText]]; +} + -(void) viewDidLoad { [super viewDidLoad]; @@ -160,8 +198,12 @@ -(void) viewDidLoad { [self.motdTextView setFormattedText:[self.sessionManager.siteConfiguration valueForKey:@"motd"]]; self.motdTextView.delegate = self; - // Create queue buttons - [self createQueueButtons]; + /// if there are open queues to join + if ([self canJoinAtLeastOneQueue]) + [self createQueueButtons]; /// Create queue buttons + else + [self createNoQueueText]; /// Let the user knows there is no open queue to join. + // Rounded button corners self.closeWindowButton.layer.cornerRadius = self.closeWindowButton.bounds.size.height / 2; diff --git a/NinchatSDK/UI/ViewControllers/QueueView/NINQueueViewController.m b/NinchatSDK/UI/ViewControllers/QueueView/NINQueueViewController.m index 2c44b22..fab6bc4 100644 --- a/NinchatSDK/UI/ViewControllers/QueueView/NINQueueViewController.m +++ b/NinchatSDK/UI/ViewControllers/QueueView/NINQueueViewController.m @@ -17,6 +17,7 @@ #import "UIButton+Ninchat.h" // UI strings +static NSString* const kNoQueueText = @"noQueuesText"; static NSString* const kQueuePositionN = @"Joined audience queue {{audienceQueue.queue_attrs.name}}, you are at position {{audienceQueue.queue_position}}."; static NSString* const kQueuePositionNext = @"Joined audience queue {{audienceQueue.queue_attrs.name}}, you are next."; static NSString* const kCloseChatText = @"Close chat"; @@ -75,22 +76,30 @@ -(void) applyAssetOverrides { [self.closeChatButton overrideAssetsWithSession:self.sessionManager.ninchatSession]; } --(void) connectToQueueWithId:(NSString*)queueId { +/// https://github.com/somia/ninchat-sdk-ios/issues/68 +-(void) connectToQueue:(NINQueue*)queue { + if (queue.isClosed) { + [self.queueInfoTextView setFormattedText:[self.sessionManager.siteConfiguration valueForKey:kNoQueueText]]; + return; + } + [self connectToQueueWithId:queue.queueID]; +} + +- (void)connectToQueueWithId:(NSString*)queueID { __weak typeof(self) weakSelf = self; - - [self.sessionManager joinQueueWithId:queueId progress:^(NSError * _Nullable error, NSInteger queuePosition) { - + [self.sessionManager joinQueueWithId:queueID progress:^(NSError * _Nullable error, NSInteger queuePosition) { + if (error != nil) { // Failed to join the queue [self.sessionManager.ninchatSession sdklog:@"Failed to join the queue: %@", error]; } - + if (queuePosition == 1) { [weakSelf.queueInfoTextView setFormattedText:[weakSelf.sessionManager translation:kQueuePositionNext formatParams:@{@"audienceQueue.queue_attrs.name": weakSelf.queueToJoin.name}]]; } else { [weakSelf.queueInfoTextView setFormattedText:[weakSelf.sessionManager translation:kQueuePositionN formatParams:@{@"audienceQueue.queue_position": @(queuePosition).stringValue, @"audienceQueue.queue_attrs.name": weakSelf.queueToJoin.name}]]; } - + // Apply color override UIColor* textTopColor = [weakSelf.sessionManager.ninchatSession overrideColorAssetForKey:NINColorAssetTextTop]; if (textTopColor != nil) { @@ -170,7 +179,7 @@ -(void) viewDidLoad { // Connect to the queue [[NSNotificationCenter defaultCenter] removeObserver:self name:kNINQueuedNotification object:nil]; - [self connectToQueueWithId:self.queueToJoin.queueID]; + [self connectToQueue:self.queueToJoin]; } @end diff --git a/NinchatSDK/Utils/Entities/NINQueue.h b/NinchatSDK/Utils/Entities/NINQueue.h index 69d6151..8b3463a 100644 --- a/NinchatSDK/Utils/Entities/NINQueue.h +++ b/NinchatSDK/Utils/Entities/NINQueue.h @@ -14,7 +14,8 @@ @property (nonatomic, strong, readonly) NSString* queueID; @property (nonatomic, strong, readonly) NSString* name; +@property (nonatomic, assign, readonly) BOOL isClosed; -+(NINQueue*) queueWithId:(NSString*)queueId andName:(NSString*)name; ++(NINQueue*) queueWithId:(NSString*)queueId andName:(NSString*)name isClosed:(BOOL)isClosed; @end diff --git a/NinchatSDK/Utils/Entities/NINQueue.m b/NinchatSDK/Utils/Entities/NINQueue.m index 055d0b3..f9167f9 100644 --- a/NinchatSDK/Utils/Entities/NINQueue.m +++ b/NinchatSDK/Utils/Entities/NINQueue.m @@ -13,6 +13,7 @@ @interface NINQueue () // Private writable versions of the properties @property (nonatomic, strong) NSString* queueID; @property (nonatomic, strong) NSString* name; +@property (nonatomic, assign) BOOL isClosed; @end @@ -37,10 +38,11 @@ -(NSString*) description { return [NSString stringWithFormat:@"Queue ID: %@, Name: %@", self.queueID, self.name]; } -+(NINQueue*) queueWithId:(NSString*)queueId andName:(NSString*)name { ++(NINQueue*) queueWithId:(NSString*)queueId andName:(NSString*)name isClosed:(BOOL)isClosed { NINQueue* queue = [NINQueue new]; queue.queueID = queueId; queue.name = name; + queue.isClosed = isClosed; return queue; } From b5a71fb874629947588a0e31223eb2af1da5dbdf Mon Sep 17 00:00:00 2001 From: Hassan Shahbazi Date: Sun, 29 Mar 2020 16:52:26 +0300 Subject: [PATCH 3/5] add null exception guards (#106) --- .../SessionManager/NINSessionManager.m | 13 ++++++++++--- .../NINVideoCallConsentDialog.h | 2 +- .../NINVideoCallConsentDialog.m | 10 +++++++--- NinchatSDK/en.lproj/Localizable.strings | 2 +- NinchatSDK/fi.lproj/Localizable.strings | 2 +- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/NinchatSDK/ManagersAndServices/SessionManager/NINSessionManager.m b/NinchatSDK/ManagersAndServices/SessionManager/NINSessionManager.m index 787f34e..3700f49 100644 --- a/NinchatSDK/ManagersAndServices/SessionManager/NINSessionManager.m +++ b/NinchatSDK/ManagersAndServices/SessionManager/NINSessionManager.m @@ -900,7 +900,9 @@ -(void) handleInboundMessage:(NINLowLevelClientProps*)params payload:(NINLowLeve NINChannelUser* messageUser = _channelUsers[messageUserID]; if (messageUser == nil) { NSLog(@"Message from unknown user: %@", messageUserID); - //TODO how big a problem is this? + /// This can result in crashes such as the one described in https://github.com/somia/ninchat-sdk-ios/issues/104 + /// The solution is to either return with the appropriate error + /// Or trying to handle the situation in the rest of the function where the user is injected } if ([messageType isEqualToString:kNINMessageTypeWebRTCIceCandidate] || @@ -918,12 +920,17 @@ -(void) handleInboundMessage:(NINLowLevelClientProps*)params payload:(NINLowLeve for (int i = 0; i < payload.length; i++) { // Handle a WebRTC signaling message NSDictionary* payloadDict = [NSJSONSerialization JSONObjectWithData:[payload get:i] options:0 error:&error]; - if (error != nil) { + if (error != nil || payloadDict == nil) { NSLog(@"Failed to deserialize message JSON: %@", error); return; } - postNotification(kNINWebRTCSignalNotification, @{@"messageType": messageType, @"payload": payloadDict, @"messageUser": messageUser}); + /// For now, since only https://github.com/somia/ninchat-sdk-ios/issues/104 is reported by customers, the easiest way is to handle the "null" exception here + /// Later, if we get more crashes or reports, we might think to make a permanent solution for all. + if (messageUser == nil) + postNotification(kNINWebRTCSignalNotification, @{@"messageType": messageType, @"payload": payloadDict}); + else + postNotification(kNINWebRTCSignalNotification, @{@"messageType": messageType, @"payload": payloadDict, @"messageUser": messageUser}); } return; } diff --git a/NinchatSDK/UI/CustomControls/VideoCallConsentDialog/NINVideoCallConsentDialog.h b/NinchatSDK/UI/CustomControls/VideoCallConsentDialog/NINVideoCallConsentDialog.h index 87979c7..0177ccc 100644 --- a/NinchatSDK/UI/CustomControls/VideoCallConsentDialog/NINVideoCallConsentDialog.h +++ b/NinchatSDK/UI/CustomControls/VideoCallConsentDialog/NINVideoCallConsentDialog.h @@ -25,6 +25,6 @@ typedef void (^consentDialogClosedBlock)(NINConsentDialogResult result); @interface NINVideoCallConsentDialog : UIView /** Displays the dialog on top of another view. */ -+(instancetype) showOnView:(UIView*)view forRemoteUser:(NINChannelUser*)user sessionManager:(NINSessionManager*)sessionManager closedBlock:(consentDialogClosedBlock)closedBlock; ++(instancetype _Nonnull) showOnView:(UIView* _Nonnull)view forRemoteUser:(NINChannelUser* _Nullable)user sessionManager:(NINSessionManager* _Nonnull)sessionManager closedBlock:(consentDialogClosedBlock _Nullable)closedBlock; @end diff --git a/NinchatSDK/UI/CustomControls/VideoCallConsentDialog/NINVideoCallConsentDialog.m b/NinchatSDK/UI/CustomControls/VideoCallConsentDialog/NINVideoCallConsentDialog.m index b95fed2..a1f79c4 100644 --- a/NinchatSDK/UI/CustomControls/VideoCallConsentDialog/NINVideoCallConsentDialog.m +++ b/NinchatSDK/UI/CustomControls/VideoCallConsentDialog/NINVideoCallConsentDialog.m @@ -85,7 +85,7 @@ +(NINVideoCallConsentDialog*) loadViewFromNib { #pragma mark - Public methods -+(instancetype) showOnView:(UIView*)view forRemoteUser:(NINChannelUser*)user sessionManager:(NINSessionManager*)sessionManager closedBlock:(consentDialogClosedBlock)closedBlock { ++(instancetype _Nonnull) showOnView:(UIView* _Nonnull)view forRemoteUser:(NINChannelUser* _Nullable)user sessionManager:(NINSessionManager* _Nonnull)sessionManager closedBlock:(consentDialogClosedBlock _Nullable)closedBlock { NINVideoCallConsentDialog* d = [NINVideoCallConsentDialog loadViewFromNib]; d.translatesAutoresizingMaskIntoConstraints = NO; d.closedBlock = closedBlock; @@ -95,15 +95,19 @@ +(instancetype) showOnView:(UIView*)view forRemoteUser:(NINChannelUser*)user ses // Caller's Avatar image if (agentAvatarConfig.imageOverrideUrl != nil) { [d.avatarImageView setImageWithURL:[NSURL URLWithString:agentAvatarConfig.imageOverrideUrl]]; - } else { + } else if (user != nil) { [d.avatarImageView setImageWithURL:[NSURL URLWithString:user.iconURL]]; + } else { + d.avatarImageView.image = [UIImage imageNamed:@"icon_avatar_other" inBundle:findResourceBundle() compatibleWithTraitCollection:nil]; } // Caller's name if (agentAvatarConfig.nameOverride != nil) { d.usernameLabel.text = agentAvatarConfig.nameOverride; - } else { + } else if (user != nil) { d.usernameLabel.text = user.displayName; + } else { + d.usernameLabel.text = NSLocalizedStringFromTableInBundle(@"Guest", @"Localizable", findResourceBundle(), @""); } [d applyAssetOverrides:sessionManager.ninchatSession]; diff --git a/NinchatSDK/en.lproj/Localizable.strings b/NinchatSDK/en.lproj/Localizable.strings index b5360a3..76e2841 100644 --- a/NinchatSDK/en.lproj/Localizable.strings +++ b/NinchatSDK/en.lproj/Localizable.strings @@ -8,4 +8,4 @@ "Camera" = "Camera"; "Photo Library" = "Photo Library"; - +"Guest" = "Guest"; \ No newline at end of file diff --git a/NinchatSDK/fi.lproj/Localizable.strings b/NinchatSDK/fi.lproj/Localizable.strings index 43fe976..68697d2 100644 --- a/NinchatSDK/fi.lproj/Localizable.strings +++ b/NinchatSDK/fi.lproj/Localizable.strings @@ -8,4 +8,4 @@ "Camera" = "Kamera"; "Photo Library" = "Kuvat"; - +"Guest" = "Vieras"; \ No newline at end of file From 9dcc96d0f145a71d01084450cb0aa6c0055d2336 Mon Sep 17 00:00:00 2001 From: Hassan Shahbazi Date: Tue, 31 Mar 2020 20:12:51 +0300 Subject: [PATCH 4/5] update dependecies to remove AppStore warnings --- NinchatSDK.podspec | 4 ++-- NinchatSDK.xcodeproj/project.pbxproj | 4 ++-- .../ChatViewController/NINChatViewController.m | 2 +- NinchatSDK/Utils/NINUtils.m | 17 ++++++++--------- Podfile | 2 +- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/NinchatSDK.podspec b/NinchatSDK.podspec index bc7b6fe..b235b15 100644 --- a/NinchatSDK.podspec +++ b/NinchatSDK.podspec @@ -40,9 +40,9 @@ Pod::Spec.new do |s| s.static_framework = true # Cocoapods dependencies - s.dependency "AFNetworking", "~> 3.0" + s.dependency "AFNetworking" s.dependency "NinchatLowLevelClient" - s.dependency "GoogleWebRTC", "~> 1.1" + s.dependency "GoogleWebRTC", "~> 1.0" s.module_name = "NinchatSDK" s.requires_arc = true diff --git a/NinchatSDK.xcodeproj/project.pbxproj b/NinchatSDK.xcodeproj/project.pbxproj index 5b0cbf5..6c2602f 100644 --- a/NinchatSDK.xcodeproj/project.pbxproj +++ b/NinchatSDK.xcodeproj/project.pbxproj @@ -1237,7 +1237,7 @@ "-framework", "\"CoreGraphics\"", "-framework", - "\"MobileCoreServices\"", + "\"CoreServices\"", "-framework", "\"NinchatLowLevelClient\"", "-framework", @@ -1292,7 +1292,7 @@ "-framework", "\"CoreGraphics\"", "-framework", - "\"MobileCoreServices\"", + "\"CoreServices\"", "-framework", "\"NinchatLowLevelClient\"", "-framework", diff --git a/NinchatSDK/UI/ViewControllers/ChatViewController/NINChatViewController.m b/NinchatSDK/UI/ViewControllers/ChatViewController/NINChatViewController.m index 2d18d51..53f270a 100644 --- a/NinchatSDK/UI/ViewControllers/ChatViewController/NINChatViewController.m +++ b/NinchatSDK/UI/ViewControllers/ChatViewController/NINChatViewController.m @@ -6,7 +6,7 @@ // Copyright © 2018 Somia Reality Oy. All rights reserved. // -@import MobileCoreServices; +@import CoreServices; @import AVFoundation; @import AVKit; @import Photos; diff --git a/NinchatSDK/Utils/NINUtils.m b/NinchatSDK/Utils/NINUtils.m index 8f9ff1d..403d8e5 100644 --- a/NinchatSDK/Utils/NINUtils.m +++ b/NinchatSDK/Utils/NINUtils.m @@ -7,9 +7,8 @@ // #import - -@import AFNetworking; - +#import +#import #import "NINUtils.h" #import "NINInitialViewController.h" @@ -92,6 +91,7 @@ id fetchNotification(NSString* notificationName, notificationBlock _Nonnull bloc void fetchSiteConfig(NSString* serverAddress, NSString* configurationKey, fetchSiteConfigCallbackBlock callbackBlock) { NSString* url = [NSString stringWithFormat:kSiteConfigUrlPattern, serverAddress, configurationKey]; + NSURLRequest *req = [[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:url]]; void (^callCallback)(NSDictionary* config, NSError* error) = ^(NSDictionary* config, NSError* error) { runOnMainThread(^{ @@ -100,14 +100,13 @@ void fetchSiteConfig(NSString* serverAddress, NSString* configurationKey, fetchS }; AFHTTPSessionManager* manager = [AFHTTPSessionManager manager]; - [manager GET:url parameters:nil progress:nil success:^(NSURLSessionTask* task, id responseObject) { - if ([responseObject isKindOfClass:[NSDictionary class]]) { + [manager dataTaskWithRequest:req uploadProgress:nil downloadProgress:nil completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) { + if (error != nil) + callCallback(nil, error); + else if ([responseObject isKindOfClass:[NSDictionary class]]) callCallback((NSDictionary*)responseObject, nil); - } else { + else callCallback(nil, newError([NSString stringWithFormat:@"Invalid responseObject class: %@", [responseObject class]])); - } - } failure:^(NSURLSessionTask *operation, NSError *error) { - callCallback(nil, error); }]; } diff --git a/Podfile b/Podfile index b73387c..79d7b59 100644 --- a/Podfile +++ b/Podfile @@ -7,7 +7,7 @@ source 'https://cdn.cocoapods.org/' source 'https://github.com/somia/ninchat-podspecs.git' def all_pods - pod 'AFNetworking', '~> 3.0' + pod 'AFNetworking' pod 'NinchatLowLevelClient', '~> 0.0.40' pod 'GoogleWebRTC', '~> 1.1' end From 8cd5e2b26c5bec8b97a5c42fd67782c03e7bdf85 Mon Sep 17 00:00:00 2001 From: Hassan Shahbazi Date: Tue, 31 Mar 2020 20:30:49 +0300 Subject: [PATCH 5/5] resolve the bug with fetching site config --- NinchatSDK/Utils/NINUtils.m | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/NinchatSDK/Utils/NINUtils.m b/NinchatSDK/Utils/NINUtils.m index 403d8e5..c42e332 100644 --- a/NinchatSDK/Utils/NINUtils.m +++ b/NinchatSDK/Utils/NINUtils.m @@ -91,7 +91,6 @@ id fetchNotification(NSString* notificationName, notificationBlock _Nonnull bloc void fetchSiteConfig(NSString* serverAddress, NSString* configurationKey, fetchSiteConfigCallbackBlock callbackBlock) { NSString* url = [NSString stringWithFormat:kSiteConfigUrlPattern, serverAddress, configurationKey]; - NSURLRequest *req = [[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:url]]; void (^callCallback)(NSDictionary* config, NSError* error) = ^(NSDictionary* config, NSError* error) { runOnMainThread(^{ @@ -99,14 +98,13 @@ void fetchSiteConfig(NSString* serverAddress, NSString* configurationKey, fetchS }); }; - AFHTTPSessionManager* manager = [AFHTTPSessionManager manager]; - [manager dataTaskWithRequest:req uploadProgress:nil downloadProgress:nil completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) { - if (error != nil) - callCallback(nil, error); - else if ([responseObject isKindOfClass:[NSDictionary class]]) + [[AFHTTPSessionManager manager] GET:url parameters:nil headers:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) { + if ([responseObject isKindOfClass:[NSDictionary class]]) callCallback((NSDictionary*)responseObject, nil); else callCallback(nil, newError([NSString stringWithFormat:@"Invalid responseObject class: %@", [responseObject class]])); + } failure:^(NSURLSessionDataTask *task, NSError *error) { + callCallback(nil, error); }]; }